0

How can I get the values in Check box while loop in php. Pls give me some tips to get the values from the below php code.

$sql=mysql_query("select * from tree");


while ($result = mysql_fetch_array($sql)) 
{ 
echo  "<br>";

echo  "<label> <input type=checkbox name=Test value=checkbox id=Test_0 > $result[fruit] |  $$result[fruit_charges] </label> <br >";

echo  "<br>";
}
echo "<br><input type=submit name=Search id=button value=search />";
2
Contributors
1
Reply
6
Views
7 Years
Discussion Span
Last Post by phpology
0

Now the below set of code will basically display x amount of checkboxes where the user can select more then one box. Now you will notice that in the checkbox code, the name has []. This is a feature that allows the selected values to pass into PHP as an array when you submit the form.

<?php 
$sql=mysql_query("select * from tree") or die(mysql_error());
while ($result = mysql_fetch_array($sql)) 
{ 
	echo  "<br>";
	
	echo  "<label> <input type=\"checkbox\" name=\"test[]\" value=\"checkbox\" id="\".$result[fruit_charges]."\">".$result[fruit]." |  ".$result[fruit_charges] ".</label> <br >";
	echo  "<br>";
}
echo "<br><input type=\"submit\" name=\"Search\" id=\"button\" value=\"search\" />";
?>

This code will basically print out what the users have selected once submit.

print_r($_POST);

Try that for a start

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.