Hi folks,
Ok, have a list of properties dynamically generated, I want the properties that Joe has selected to appear already checked when generating the form. As you can see by this link:
http://www.stagnellfox.co.uk/html/array_test.php
It’s not working.
Here’s my code
//select all the properties selected by someone
$query2 = "SELECT first_name, properties FROM applicants WHERE app_ID = '184'";
$result2 = mysql_query($query2, $stagnellfox) or die(mysql_error());
$row2 = mysql_fetch_array($result2);
$total2 = mysql_num_rows($result2);
//echo the properties selected
echo ''.$row2['first_name'].' selected the following properties<br>';
$arr = split("
", $row2['properties'] );
foreach($arr as $key => $value2){
echo "$value2<br>";
}
echo "<br>";
//select all the property names from the properties database
$query1 = "SELECT prop_Name FROM properties ORDER BY prop_Name ASC";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_array($result1);
//build form
echo '<form name="form1" method="post" action="'.$_SERVER["PHP_SELF"].'">';
echo '<input name="sub" type="hidden" value="y">';
//list all the properties with a checkbox for each
while($row1 = mysql_fetch_array($result1)){
$name = $row1['prop_Name'];
//match values?
if($name == $value2){
$selected = "checked";
}
echo "<input name='properties[]' type='checkbox' value='$name'".$selected.">$name";
echo "<br>";
}
//end form
echo '<input type="submit" name="Submit" value="Submit">';
echo "</form>";
//process results
if($_POST['sub'] == 'y'){
//loop through each selected
$props = NULL;
foreach($_POST['properties'] as $key => $value){
$props .= "$value<br>";
}
}
//echo selected properties
echo $props;
echo "<br>";
?>
Any help, greatly appreciated.
Thanks