Hello, I am a little stuck with a project I have as a beginner php programmer.
I am making a 3 tier drop down box system for a tire searching engine.
By that I mean that someone looking for tires compatible with their respective cars can choose 1. Make of car 2. Model of car 3. Year of car and then subsequently be presented with the list of tires compatible with it.
So I came across a script and I have been modifying it but I cannot for the life of me figure out what I have done wrong so I am just gonna straight out copy and paste the back end of the php script. The problem is that I can choose the Brand, and Model fine, but I can’t get it to select the year…
[php]
<? header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header("content-type: application/x-javascript; charset=tis-620"); $data=$_GET['data']; $val=$_GET['val']; $model=$_GET['model']; $dbhost = "localhost"; $dbuser = "root"; $dbpass = "pass"; $dbname = "tires"; mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server"); // the following is to populate the brands... ford, gm, honda etc.... if ($data=='brand') { echo "n"; echo "brandn"; $result=mysql_db_query($dbname,"select `id`, `brand` from brand order by `brand`"); while(list($id, $name)=mysql_fetch_array($result)){ echo "$name n" ; } // the following is to populate the respective models... eg mustang, hummer, civic... the model_id field is a number respective to the number designated to a brand... for example Ford might be 1 so the model_id for mustang would be 1, as would the model_id for shelby for example. } else if ($data=='model') { echo "n"; echo "modeln"; $result=mysql_db_query($dbname,"SELECT `id`, `model` FROM model WHERE `model_id` = '$val' ORDER BY `model` "); while(list($id, $name)=mysql_fetch_array($result)){ echo "$name n" ; } // and the following is to populate the years or submodels of the cars......year_id supposedly is the link between the model and year drop down boxes where by year_id is the model name and year is well the year. For example, year_id for a Ford mustang 2004 would be "mustang". In other words year_id links to the model field of the model table. } else if ($data=='year') { echo "n"; echo "yearn"; $result=mysql_db_query($dbname,"SELECT `id`, `year` FROM year WHERE `year_id` = '$model' ORDER BY `year` ")or die(mysql_error()); while(list($id, $name)=mysql_fetch_array($result)){ echo "$name n" ; } } echo "n"; ?>[/php]
I can paste the ajax script too but I don’t want to get on anyone’s nerves with my very first post here! I think the problem is that the variable for $model hasnt been defined. Any pointers would be much appreciated
Thanks.