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 />";

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.