ainoy31 Posted July 8, 2008 Share Posted July 8, 2008 Hello- I am trying to get data from the database and populate the data in a drop down menu but it does not seem to work. $sql = "SELECT DISTINCT make FROM car"; $result = mysql_query($sql) or die("Error: " . mysql_error()); $rows = mysql_num_rows($result); //gives me the total rows found to use as my counter ?> <select name="make"> <option value="">Make</option> <? $x = 0; while($x < $rows) { $make = mysql_result($result, $x, 'make'); ?> <option value="<?=$make[$x]?>"><? echo $make[$x];?></option> </select> <? $x++; } ?> There should be 51 records but I get nothing in the select menu. Much appreciation. Link to comment https://forums.phpfreaks.com/topic/113687-solved-query-issue/ Share on other sites More sharing options...
Barand Posted July 8, 2008 Share Posted July 8, 2008 "$make[$x]" in the options should be just "$make". or try <?php $sql = "SELECT DISTINCT make FROM car"; $result = mysql_query($sql) or die("Error: " . mysql_error()); while ($row = mysql_fetch_assoc($result)) { printf("<option value='%s'>%s</option>\n", $row['make'], $row['make']); } ?> Link to comment https://forums.phpfreaks.com/topic/113687-solved-query-issue/#findComment-584236 Share on other sites More sharing options...
ainoy31 Posted July 8, 2008 Author Share Posted July 8, 2008 Thanks for the suggestion. It is working. Why did you use %s? Link to comment https://forums.phpfreaks.com/topic/113687-solved-query-issue/#findComment-584242 Share on other sites More sharing options...
Barand Posted July 8, 2008 Share Posted July 8, 2008 Why did you use %s? Because I thought the car makes would probably be string values Link to comment https://forums.phpfreaks.com/topic/113687-solved-query-issue/#findComment-584346 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.