Jump to content

[SOLVED] Query Issue


ainoy31

Recommended Posts

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

"$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.