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. Quote Link to comment 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']); } ?> Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.