I'm writing a script, and part of that script has to pull data out of a database and display it in an html select field.
Below is my code with. It all works fine. My issue is that instead of displaying all of the database table rows inside of ONE select field, a new select field is generated for every table row.
How can I alter the code to display all of the rows in ONE SINGLE select field? Any help is much appreciated.
PHP Code:
<?php
$username="...";
$password="...";
$database="...";
$host=".....";
mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news_cats";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$f1=mysql_result($result, $i, "cat");
echo "<select>";
echo "<option name=\"cat\">$f1</option>";
echo "</select>";
$i++;
}
?>