Hello,
I am trying to create two drop down lists which will be populated by my MySQL database. I want these lists to be identical. I can get the first list populated but the second is left empty. Here is my code:
<?
$connection = mysql_connect("localhost","root","") or die ("Couldnt Connect to MySQL server");
$db = mysql_select_db("ward",$connection) or die ("Couldnt Select Database!");
$sql = "select first_name, last_name, home_phone, id from members where gender=\"M\" order by last_name asc";
$sql_result = mysql_query($sql,$connection) or die ("Couldnt Execute SQL query");
$row = mysql_fetch_array($sql_result);
echo "
<head>
<title>Untitled Document</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
</head>
<body bgcolor=\"#FFFFFF\" text=\"#000000\">
<h1>Home Teaching Assignments</h1>
<form method=\"post\" action=\"add_ht_assignments.php\">
<select name=\"companion1\">
<option value=\"\">Select First Companion</option>
";
while ($row = mysql_fetch_array($sql_result)) {
$first_name = $row["first_name"];
$last_name = $row["last_name"];
$id = $row["id"];
echo "
<option value=\"$id\">$last_name, $first_name</option>
";
}
echo "
</select>
<br>
<select name =\"companion2\">
<option value=\"\">Select Second Companion</option>
";
while ($row = mysql_fetch_array($sql_result)) {
$first_name = $row["first_name"];
$last_name = $row["last_name"];
$id = $row["id"];
echo"
<option value=\"id\">$last_name, $first_name</>
";
}
echo "
</form>
</body>
";
?>
Any help anyone could provide would be great! Oh, and if you want to see this file in use go to http://12.23.79.52/ht_assign.php