joesaddigh Posted March 10, 2009 Share Posted March 10, 2009 Hi, I have been trying to populate a listbox from the database and control another one based on the choice of the first. When i view my page the first list box does not display any text but it has the correct amount of options in there (they are blank) so it is returning the correct values from the db. The code is below: <?php @$coursetitle=$_GET['coursetitle']; ///////// Getting the data from Mysql table for first list box////////// $querytitle=mysql_query("SELECT DISTINCT CourseTitle FROM course"); if(isset($coursetitle) and strlen($coursetitle) > 0){ $querylevel=mysql_query("SELECT DISTINCT courselevel FROM course where coursetitle=$coursetitle"); } else{$querylevel=mysql_query("SELECT DISTINCT courselevel FROM course"); } echo "<form method=post name=f1 action='dd-check.php'>"; ////////// Starting of first drop downlist ///////// echo "<select name='coursetitle' onchange=\"reload(this.form)\"><option value=''>Select Course</option>"; while($noticia2 = mysql_fetch_array($querytitle)) { if($noticia2['coursetitle']==@$coursetitle) { echo "<option selected value='$noticia2[coursetitle]'></option>"."<BR>"; } else { echo "<option value='$noticia2[coursetitle]'>$noticia2[coursetitle]</option>"; } } echo "</select>"; ////////// Starting of second drop downlist ///////// echo "<select name='courselevel'><option value=''>Select Level</option>"; while($noticia = mysql_fetch_array($querylevel)) { echo "<option value='$noticia[courselevel]'>$noticia[courselevel]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/148751-double-list-boxes/ Share on other sites More sharing options...
DocSeuss Posted March 10, 2009 Share Posted March 10, 2009 mysql_fetch_array returns a numbered array not an associative one. use mysql_fetch_assoc() or mysql_fetch_array($result, MYSQL_ASSOC); Link to comment https://forums.phpfreaks.com/topic/148751-double-list-boxes/#findComment-781061 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.