I had this challenge and laserlight and leatherback helped me thru it, but now I am trying to get the data for this dynamic array from a query and I get...
---drop down menu start---
1 (1st record, I just get a value)
2 (end record, I just get a value)
3 (3rd record, I just get a value)
John Doe (I get the correct name)
---drop down menu end---
I know I am close, but I've tried many variations with no success.
So I throw myself on the mercy of the forum.
$query="SELECT * FROM quizzes WHERE TeachersEmail='".$TeachersEmail."' ORDER BY StudentsName ASC";
//echo $sql.'<br /><br />';
$result = mysql_query($query) or die(mysql_error());
$num_rows = mysql_num_rows($result);
echo '<br /><br />The number of rows is '.$num_rows.'<br /><br />';
while ($myrow = mysql_fetch_array($result))
{
$name = $myrow['StudentsName'];
// initialize array, with empty start option:
$names = array("" => " ");
for ($i = 1; $i < $num_rows; ++$i)
{
$names["$i"] = "$i";
}
$names["$num_rows"] = $myrow['StudentsName'];
}
$x='1'; //tabindex value
$list = makeDropList('names',$names,$names);
the code for 'makeDropList is ...
function makeDropList($name,$list,$selected="") {
// $name select name
// $list array of value, label pair
// $selected selected value
global $x;
while(list($value,$label) = each($list)) {
$options .= '<option value="'.$value.'">'.$label.'</option>';
}
$dropList = '<select name="'.$name.'" tabindex="'.$x.'">'.$options.'</select>'."\n";
$dropList = ereg_replace("value=\"$selected\"","value=\"$selected\" selected",$dropList);
return $dropList;
}
What am I misssing here???
Thanks a bunch in advance (as usual),
Don