Jump to content

Semi Amateur Requesting Help on MySQL / PHP


rostros

Recommended Posts

Ive been using Dreamweaver for a while now and have been building dynamic sites with PHP / MySQL which is great fun but recently i have hit a break wall on a latest development.

This is the current issue where im stuck ,

In one table which contains these details

---------------------------------
vehicle_id
vehicle_manufacturer
vehicle_model
vehicle_added
----------------------------------

On my .PHP Page I have created a Form, with a List Box and  created connection via MySQL to call all the Vehicles in this list.

Problem :

The List Box only contains either Manufacturer or Model Type not both at once, so I created another List Box in the Form so when the user selects the vehicle manufacturer it then filters the model dropdown box depending on the manufacturer.

I know there is way of using javascript to filter the options on selection but i wish to use the options stored in MySQL.


How do you program this Drop Down Box's that use MySQL Data, and how do you Filter them ? would you use $URL Variables or $FORM Variables or something different.

Any help would be great.








ok I am not sure exactly what you meant. But here is what I would do if I wanted a dropdown box with the vehicle_manufacturer vehicle_model in it.

[code=php:0]
<select size="20" name="whatever">
<?php
$sql ="SELECT vechicle_manufacturer, vehicle_model FROM your_table";
$get_vechicles = mysql_query($sql);

if (!get_vechicles) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}
if (mysql_num_rows($get_vechicles) == 0) {
    echo "There are no vechicles in the database";
    exit;
}

while ($row = mysql_fetch_assoc($get_vechicles)) {
    echo '<option>' . $row['vechicle_model'] . ' ' . $row['vechicle_manufacturer'] .'</option>';
}
mysql_free_result($get_vechicles);
?>
</select>
[/code]

Hope this helps,
TOM

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.