Forum Moderators: coopster
if(isset($_GET['address'])) {
foreach( ($_GET['address']) as $value){
echo $value; }
}
Select data from table ;
$address_no = $row[0] ;
while ($row = mysql_fetch_array($result)) {
<input type="checkbox" name="address[]" value="<? echo $address_no;?>" />
}
HTML
<input type="checkbox" name="address[]" value="<? echo $address_no;?>" checked >
XHTML
<input type="checkbox" name="address[]" value="<? echo $address_no;?>" checked="yes"/>
<edit>
You may need to check the html version...I havent used that version for a good few years so may well be wrong. However as you were closing the tag I guess you are xhtml'ing :)
[edited by: PHP_Chimp at 9:31 pm (utc) on Nov. 28, 2007]
Try what I have below to see what I mean about only the checked versions appearing in the $_GET array.
There is also the for loop in there that you could use to loop through the ['address'] array to find checked values.
test.php
<?php
if(isset($_GET['address'])) {
echo '<pre>';
print_r($_GET);
echo '</pre>';
$length = count($_GET['address']);
for ($i=0; $i<$length; $i++) {
if($_GET['address'][$i] == 'Some_value'){
echo '<input type="checkbox" name="address[]" value="some_value" checked="checked" />';
}
}
}
else {
?>
<html>
<head>
</head>
<body>
<form method="get" action="test.php">
<input type="checkbox" name="address[]" value="Some_value" checked="checked" />
<input type="checkbox" name="address[]" value="Some_value_1" />
<input type="checkbox" name="address[]" value="Some_value_2" />
<input type="submit" />
</form>
</body>
</html>
<?php
}
?>
[edited by: PHP_Chimp at 10:47 pm (utc) on Nov. 28, 2007]