Any idea why this function won't work? Im trying to create a dropdown menu for each row, but its not spitting out the dropdown properly...
Here is the code:
<?php
$db = mysql_connect ("localhost", "root");
mysql_select_db("pcs",$db);
function namedropdown ($x)
{
$members = mysql_query("SELECT * FROM member ORDER BY lastname ASC");
while ($row = mysql_fetch_array($members))
{
if ($row["member_id"] == "$x")
{
printf("<option value=\"%s\" selected>%s, %s</option>\n", $row["member_id"], $row["lastname"], $row["firstname"]);
}
else
{
printf("<option value=\"%s\">%s, %s</option>\n", $row["member_id"], $row["lastname"], $row["firstname"]);
}
}
}
if ($Submit)
{
$sql1="UPDATE event SET location='$location', title='$title', phone='$phone', date='$date', teams='$teams', updated='NOW()' WHERE event_id='$event_id'";
mysql_query($sql1);
$b=count($crew_id);
for ($a=0;$a<=$b;$a++)
{
$sql2="UPDATE crew SET member_id='$member_id[$a]', position_id='$position_id[$a]' WHERE crew_id='$crew_id[$a]'";
mysql_query($sql2);
}
print '<br><br>Number of Rows Updated: '.$b;
}
else
{
$a=0;
printf("<form name=\"form1\" method=\"post\" action=\"%s\">\n", $PHP_SELF);
print "<table>\n";
$result1 = mysql_query("SELECT * FROM event WHERE event_id='$event_id'");
$myrow1 = mysql_fetch_array($result1);
printf("<tr><td colspan=\"2\"><input type=\"hidden\" name=\"event_id\" value=\"%s\"><input type=\"text\" name=\"location\" value=\"%s\"></td></tr>\n", $myrow1["event_id"], $myrow1["location"]);
printf("<tr><td colspan=\"2\"><input type=\"text\" name=\"title\" value=\"%s\"></td></tr>\n", $myrow1["title"]);
printf("<tr><td colspan=\"2\"><input type=\"text\" name=\"phone\" value=\"%s\"></td></tr>\n", $myrow1["phone"]);
printf("<tr><td colspan=\"2\"><input type=\"text\" name=\"date\" value=\"%s\"></td></tr>\n", $myrow1["date"]);
printf("<tr><td colspan=\"2\"><input type=\"text\" name=\"teams\" value=\"%s\"></td></tr>\n", $myrow1["teams"]);
$result2 = mysql_query("SELECT * FROM crew WHERE event_id='$event_id'");
while ($myrow2 = mysql_fetch_array($result2))
{
printf("<tr><td colspan=\"2\"><input type=\"hidden\" name=\"crew_id[%s]\" value=\"%s\"><select name=\"member_id[%s]\">%s</select></td></tr>\n", $a, $myrow2["crew_id"], $a, namedropdown($myrow2[member_id]));
$a++;
}
printf("<tr><td colspan=\"2\"><input type=\"submit\" name=\"Submit\" value=\"Submit\"></td></tr>\n");
printf("<table>\n");
printf("</form>\n");
}
?>
Here is the HTML it is spitting out...
<form name="form1" method="post" action="/~matt/PCS Website/crewsheets/update/update.php">
<table>
<tr><td colspan="2"><input type="hidden" name="event_id" value="1"><input type="text" name="location" value="Airlines Center"></td></tr>
<tr><td colspan="2"><input type="text" name="title" value="Replay Crew Information"></td></tr>
<tr><td colspan="2"><input type="text" name="phone" value="(214) 665-4588"></td></tr>
<tr><td colspan="2"><input type="text" name="date" value="2003-06-12 19:30:00"></td></tr>
<tr><td colspan="2"><input type="text" name="teams" value="Mavs vs. New Jersey"></td></tr>
<option value="1">Allen, Larry</option>
<option value="2" selected>Campbell, Dayne</option>
<option value="3">Rebstock, Ben</option>
<tr><td colspan="2"><input type="hidden" name="crew_id[0]" value="1"><select name="member_id[0]"></select></td></tr>
<option value="1" selected>Allen, Larry</option>
<option value="2">Campbell, Dayne</option>
<option value="3">Rebstock, Ben</option>
<tr><td colspan="2"><input type="hidden" name="crew_id[1]" value="2"><select name="member_id[1]"></select></td></tr>
<option value="1">Allen, Larry</option>
<option value="2" selected>Campbell, Dayne</option>
<option value="3">Rebstock, Ben</option>
<tr><td colspan="2"><input type="hidden" name="crew_id[2]" value="3"><select name="member_id[2]"></select></td></tr>
<tr><td colspan="2"><input type="submit" name="Submit" value="Submit"></td></tr>
<table>
</form>