Jump to content


Photo

Semi Amateur Requesting Help on MySQL / PHP


  • Please log in to reply
1 reply to this topic

#1 rostros

rostros
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 28 July 2006 - 03:09 PM

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.










#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 28 July 2006 - 05:39 PM

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.

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

Hope this helps,
TOM

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users