array problem
Posted: Tue May 01, 2007 2:54 pm
I have a form with checkboxes that I want users to be able to log back in and edit whenever needed and I want their previous selections to remain checked. The problem I'm having is that my code will only return the 2nd and 3rd entry in my array. So if a person previously had 5 options checked, my form is only showing 2 of the options checked. I can't seem to figure out what I'm doing wrong. I have about 60 options in my form but have shortened it to just 2. See below...
Code: Select all
$sql = "SELECT * FROM `signup2` WHERE username = '".$_SESSION['username']."' AND password = '".$_SESSION['password']."'";
$result = mysql_query($sql,$db);
while ($newArray = mysql_fetch_array($result))
{
$activities = $newArray['activities'];
$activity = explode(",", $activities);
$arrayValues = array("$activity[0]","$activity[1]","$activity[2]","$activity[3]","$activity[4]","$activity[5]","$activity[6]","$activity[7]","$activity[8]","$activity[9]","$activity[10]");
if (in_array("Academic Decathalon",$arrayValues)) {
echo "<input name=\"activities[]\" type=\"checkbox\" value=\"Academic Decathalon\" checked>";
} else {
echo "<input name=\"activities[]\" type=\"checkbox\" value=\"Academic Decathalon\" >";
}
echo "Academic Decathalon</td>
<td width=\"178\">";
if (in_array("Aerospace Club",$arrayValues)) {
echo "<input name=\"activities[]\" type=\"checkbox\" value=\"Aerospace Club\" checked>";
} else {
echo "<input name=\"activities[]\" type=\"checkbox\" value=\"Aerospace Club\" >";
}
}