populating a listbox
Posted: Wed Feb 10, 2010 1:54 pm
Hi all, I've just started learning PHP so apologies if what I'm about to post is full on ridiculous but I'm definately stuck...
basically I'm trying to populate a listbox from a database in php myadmin, and I can do it fine jus using PHP but I'm wanting to run it through HTML as well, i dont know if i need to use _POST or _GET to make this work, or if there's some other method but any help will be appreciated, here's my code...
PHP
HTML
note: the host dbname password etc are all changed, it not being 'localhost' is definately not my issue =P
thanks in advance
basically I'm trying to populate a listbox from a database in php myadmin, and I can do it fine jus using PHP but I'm wanting to run it through HTML as well, i dont know if i need to use _POST or _GET to make this work, or if there's some other method but any help will be appreciated, here's my code...
PHP
Code: Select all
<?php
$con = mysql_connect("host", "database", "password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result = mysql_query("SELECT * FROM students");
echo "<table border='0'>";
echo "<tr>";
echo "<td rowspan=\"6\">";
echo "<select size=10 name=userList mutiple>";
while($row = mysql_fetch_array($result))
{
echo "<option>$row[sname], $row[fname]</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
echo "</table>";
mysql_close($con);
?>Code: Select all
<html>
<body>
<form action="manageuser.php" method="post">
<table border="0">
<tr>
<td rowspan="6">
<select size=10 name=userList mutiple>
<option value="fname">fname</option>
<option value="fname">fname</option>
<option value="fname">fname</option>
</select>
</td>
<td>
User ID:
</td>
</tr>
</form>
</body>
</html>thanks in advance