RE: [PHP-DB] Checkboxes with mySQL

From: Date: Fri, 07 Sep 2001 13:20:47 +0000
Subject: RE: [PHP-DB] Checkboxes with mySQL
Groups: php.db 
Request: Send a blank email to php-db+get-12249@lists.php.net to get a copy of this message
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:cilfa@euronet.nl] Sent: Friday, September 07, 2001 7:38 AM To: php-db@lists.php.net 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: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#12249) next »