I'm using the connection below to connect to my database and create a select list box. I also have a table called testtable with two fields.
ID
Name
The ID field is an auto number field. The Name field contains the names I want to appear in a drop down list box. I've tried using this code but nothing appears in the drop down. What coud be the problem?
<?
$host = "localhost";
$dbname = "CommunityServiceTracking";
$User = "Anthony";
$dbpass = "";
$connection = mysql_connect("$host","$dbname","$dbpass");
$db = mysql_select_db("$dbname",$connection);
echo" <select name=\"category\"> "; //start the select box
$results= mysql_query("SELECT ID, Name from testtable Order by Cat asc",$connection);
$id = "ID";
$idname = "Name";
echo mysql_error();
if (mysql_Numrows($results)>0) //if there are records in the fields
{
$numrows=mysql_NumRows($results); //count them
$x=0;
while ($x<$numrows){ //loop through the records
$theId=mysql_result($results,$x,$id); //place each record in the variable everytime we loop
$theName=mysql_result($results,$x,$idname);
echo "<option value=\"$theId\">$theName</option>\n"; //and place it in the select
$x++;
}
}
echo "</select>";
?>