You have to check each checkbox value in you selection criteria.  Somthing
like:

$query = "UPDATE articles SET pr=1 WHERE 0";
# assume $nbr is size of array $p
for($i=0; $i<$nbr;$i++)
{
        if( isset($p[$i]) ) { $query .= "|| id=$p[$i] ";
}

This will construct a query that looks like:  UPDATE articles SET pr=1 WHERE
0 || id=1 || id=3 || id=4

The "0" in the WHERE clause is just a place holder; it saves a little
coding.

Hope this helps

rick

-----Original Message-----
From: Cilfa [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 7:38 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Checkboxes with mySQL


I have a database with articles from which I can make a selection of which
articles to show. This selection is made by a form with checkboxes.
In the mysql table is a field called "pr". If there's a "1" in this field,
the article should be shown for print, if there's a "0", it shouldn't.
     
In the code I generate a form with all the titles and checkboxes. The
checkbox values are the id's from the titles.
When I click the button, I want to see my selection.
       
The problem is this: What sql query can be used to proces the information
from the checkboxes? At the moment I use in order to change the values in
the database according to the checkbox selections:

$query = mysql_query("UPDATE articles SET pr='1' WHERE id='$p[id]'");

But it does nothing! How can I insert multiple values (from the checkbox
array) at one time in a database?

Cilfa


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to