Hi All, this is my first post (but wont be my last!)
I have created a three tier drop down function using php.
The purpose is to locate car parts.
The first drop down is make, the second is model and the third submodel.
I have created a database with these 3 columns and have added a fourth column with the actual car part data e.g 0123456
My code is below;
[php]<?php
function getTierOne()
{
$result = mysql_query(“SELECT DISTINCT make FROM carparts”)
or die(mysql_error());
while($tier = mysql_fetch_array( $result ))
{
echo '<option value="'.$tier['make'].'">'.$tier['make'].'</option>';
}
}
if($_GET[‘func’] == “drop_1” && isset($_GET[‘func’])) {
drop_1($_GET[‘drop_var’]);
}
function drop_1($drop_var)
{
include_once(‘db.php’);
$result = mysql_query(“SELECT DISTINCT model FROM carparts WHERE make=’$drop_var’”)
or die(mysql_error());
echo '<select name="drop_2" id="drop_2">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_2 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_2['make'].'">'.$drop_2['make'].'</option>';
}
echo '</select>';
echo "<script type=\"text/javascript\">
$(’#wait_2’).hide();
$(’#drop_2’).change(function(){
$(’#wait_2’).show();
$(’#result_2’).hide();
$.get(“func.php”, {
func: “drop_2”,
drop_var: $(’#drop_2’).val()
}, function(response){
$(’#result_2’).fadeOut();
setTimeout(“finishAjax_tier_three(‘result_2’, '”+escape(response)+"’)", 400);
});
return false;
});
";
}
if($_GET[‘func’] == “drop_2” && isset($_GET[‘func’])) {
drop_2($_GET[‘drop_var’]);
}
function drop_2($drop_var)
{
include_once(‘db.php’);
$result = mysql_query(“SELECT * FROM carparts WHERE model=’$drop_var’”)
or die(mysql_error());
echo '<select name="drop_3" id="drop_3">
<option value=" " disabled="disabled" selected="selected">Choose one</option>';
while($drop_3 = mysql_fetch_array( $result ))
{
echo '<option value="'.$drop_3['submodel'].'">'.$drop_3['submodel'].'</option>';
}
echo '</select> ';
echo '<input type="submit" name="submit" value="Submit" />';
}
?>[/php]
The fourth column is called “parts” - I can’t seem to workout how to print data from the fourth column when the user has selected the previous three columns - I hope this makes sense!
Thank you.