Drop down list

I’m having problems getting info from my database. I’m lost on this one.
Any help is appreciated.

$connection = mysql_connect($host,$user,$password)
or die (“couldn’t connect to server”);
$db = mysql_select_db($database,$connection)
or die (“Couldn’t select database”);
$query = “SELECT DISTINCT carmake FROM ALL_ITEMS ORDER BY carmake”;
$result = mysql_query($query)
or die (“Couldn’t execute query.”);

/* create form containing selection list */
echo "
n";

while ($row = mysql_fetch_array($result))
{
extract($row);
echo “$carTypen”;
}
echo “n”;
echo "
n";
?>

What exactly is the problem? Are you getting errors, or is nothing showing at all?

You are using mysql_fetch_array, which returns an associative array, so try changing:

extract($row); echo "$carTypen";

to:

echo "$row['carType']n";

What I’m trying to do is the following.

I made a cars database.

Database name is ALL_ITEMS

And basically all I want is that there would be a drop down box for example with Civic, Accord etc and when someone would pick one that it would select that type of cars in the database and put it on the page

What I’m trying to do is the following.

I made a cars database.

Database name is ALL_ITEMS

And basically all I want is that there would be a drop down box for example with Civic, Accord etc and when someone would pick one that it would select that type of cars in the database and put it on the page

Thanks

What I’m trying to do is the following.

I made a cars database.

Database name is ALL_ITEMS

And basically all I want is that there would be a drop down box for example with Civic, Accord etc and when someone would pick one that it would select that type of cars in the database and put it on the page

Thanks

Hi dgame27,

I could be completly wrong but i think if you don’t have anything in the categories of carmake. ie: you have the categories but no cars listed in the database under that categories, then nothing will show up?

for instance, you have makes (categories) holden, Ford, Mitsubishi but no actual cars in the table.

I think I’m learning from the same book as you and tried it out on mine. If you change the MySQL query from…
[php]
$query = “SELECT DISTINCT carmake FROM ALL_ITEMS ORDER BY carmake”;
[/php]
to (assuming you have a table listing the makes of car and assuming you named it ‘carmake’)
[php]
$query = “SELECT * FROM carmake ORDER BY carmake”;
[/php]
i think that might work. Or at least will give you a drop down menu of all the categories.

Though as I said, I could be completely wrong as I’m very new to this myself.

Database name is ALL_ITEMS
and
$query = "SELECT DISTINCT carmake FROM ALL_ITEMS ORDER BY carmake";
doesen't ring any bells to you? you are doing a query to a database NOT to a table, as Owly correctly put
$query = "SELECT * FROM carmake ORDER BY carmake";
.

so the code u ( my guess) shall try would be this; ( assuming u got at least maker & model in to ur table named “carmake”)

$mysql_select_db("ALL_ITEMS");
$ty=myslq_query('select * from carmake ');
echo("<select name=kioi>");
while ($yf=mysql_fetch_array(($ty)) {
    $maker=$yf['maker'];
    $model=$yf['model'];
    echo('<option value='.$maker.'>');
}
echo('</option>');

This is by no way validated & may be incomplete, as a matter of fact it may be wrong a some point, but i think it’ll show u the way.

i hope this becomes handy, forgiveme if not.

BTW; check your echo syntax…

cya

Thanks for all the input I will give it a try.

Sponsor our Newsletter | Privacy Policy | Terms of Service