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.








Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.