note 54810 deleted from language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Jun 2009 16:54:47 +0000 |
| Subject: | note 54810 deleted from language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157402@lists.php.net to get a copy of this message | ||
Note Submitter: Polina
----
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.