note 54810 added to language.variables.variable
| From: | Polina at osu1 dot php dot net | Date: | Fri, 15 Jul 2005 16:13:42 +0000 |
| Subject: | note 54810 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92026@lists.php.net to get a copy of this message | ||
Easy way to get a list of items selected by the user, using checkboxes and variable variables.
My form:
<?
include("mysql.inc.php");//my mysql connection
$proSQL = "SELECT * FROM products ORDER BY name"; //selecting products from DB
$pro_query = mysql_query($proSQL) or die($proSQL."<br>".mysql_error());
$pro_num = mysql_num_rows($pro_query); //number of products
print("<form action='theend.php' method='post'>");
$i=0;
while($products = mysql_fetch_object($pro_query)){
$i++;
print("<input type='checkbox' name='$i'
value='$products->name'> $products->name<br>"); //print a checkbox
with the product name
}
print("<input type='hidden' value='$pro_num'
name='products_number'>");//number of products
print("<input type='submit'></form>");
?>
theend.php :
<?
$i=0;
while($i < $products_number){
$i++;
if($$i){
$message .="$$i<br>";
}
}
print("$message");//a list of checked products
?>
This will give a list of the products selected by the user.
I usually use it to send by e-mail with other informations collected from the form.
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54810
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54810&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54810&report=yes
Search -- http://master.php.net/manage/user-notes.php