I’m having a problem I hope someone can help me settle. The following snippet was taken from the “user modification” page of my site where users can locate a pre-existing ticket and modify same. As you can see, the value is already pre-set depending which ticket has been called from mysql database and alternative value selections have been hard coded:
<p>Mechanic:
<SELECT name=\"name_id\">
<OPTION value=\"\">-- Select One --</OPTION>";
$name_array = array("Bill Griffin","Joe Chambers","Dave Tooley","Dave Sykes","Carl Johnson","Sherry Angelucci","Heather Merrill","Chuck Roseman");
foreach ($name_array as $name) {
if ($name == "$name") {
echo "<OPTION value=\"$name\"
selected>$name</OPTION>";
} else {
echo "<OPTION value=\"$name\">$name</OPTION>";
}
}
echo "</SELECT></p>
What I would like to do is instead of hard coding alternative value selections is pre-fill alternative value selections from database and I came up with this:
<p>Mechanic:
<SELECT name=\"name\">
<OPTION value=\"\">-- Select One --</OPTION>";
$sql = "SELECT name FROM personal_info ORDER BY name ASC";
$result = mysql_query($sql) or die(mysql_error());
if (!result) {
echo "An Error occurred connecting to Database!";
} else {
$name_array = mysql_fetch_row($result);
foreach($name_array as $name) {
if ($name == "$name") {
echo "<OPTION value=\"$name\"
selected>$name</OPTION>";
} else {
echo "<OPTION value=\"$name\">$name</OPTION>";
}
}
}
echo "</SELECT></p>
What I get is the form with no preselected value depending on the ticket and only the first row from the database table row comes back on the form. What am I doing wrong? Sure would appreciate anybody’s help!