populate combo box / dropdown list from mysql
-
I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>
-
I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>
komanche wrote:
$make = "SELECT make FROM cars WHERE make='".$q."' ORDER BY make"; $make = "SELECT id,value FROM make ORDER BY id";
this sequence of assignments doesn't make sense, either the first is redundant, or something is missing in between them. In future: - please show code snippets inside PRE tags; - for database-related questions explain your tables and fields. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>
Well you should try to find out if the query actually returns something. Try this
$dbResID = mysql_query ( $make, $access); if(mysql_errno($access)>0)die("the following sql: $make produced an error: ".mysql_error($access)." ");
If there is no error there check to see how many rows have been selected:echo"<p> selected rows:".mysql_num_rows($dbResID)."</p>";
And let us not forget the most important part, the html output(if you did not check it by now) there is something missing. The select tag :)echo'<select name="cars">'; while ( $row = mysql_fetch_row($dbResID) ) print "<option value=\"$row[0]\">$row[1]</option>\n"; echo'</select>';
That is all the debugging that can be done, and if nothing up there works, then there is something really wrong somewhere else. Hope this helps. P.S. Sorry about the fact that part of the code is not displayed right, but I did insert the code tags while writing.It can't rain all the time