Page 1 of 1

checkbox

Posted: Fri Jul 18, 2008 7:34 am
by sahur
my codes like this:
$data=mysql_query("SELECT* FROM data");
while($a=mysql_fetch_array($data)){
$b=$a['name'];
echo '<input type="checkbox" name="check" value='.$b.">".$b."</br>";
}
output:
[] John
[] James
[] Nicholas

$d=$_POST['check'];
echo $d;
i use this code to display the names above but its only display only one name . what codes should i use to display all the names if i check all the names above?

Re: checkbox

Posted: Fri Jul 18, 2008 7:40 am
by EverLearning
echo '<input type="checkbox" name="check[]" value='.$b.">".$b."</br>";

and since $_POST check will be an array, you won't be able to get the values with echo. You'll need somethig like

Code: Select all

 
$checked = isset($_POST['check']) ? $_POST['check'] : array();
foreach($checked as $value) {
    echo $value;
}