Hi guys this is my problem. I am making a database using mysql where i have 2 tables, one for car manufacturers and one for car models.I've already done that. I have made a php page where i have 2 drop down menus.
The first menu shows car makers(manufacturers) and the 2nd nothing. Now when a user opens the 1st menu and selects a maker , the 2nd automatically fills up with models from that car maker only and it gets its information from the database.That is every time i decide to add a new model to my database the 2nd menu (if selected) must go and search the database for all the models for that maker and show them.
Here's the code:The first menu works. It goes into the database and selects all the cars from the makers table.However the 2nd menu shows me only CHOOSE MODEL and ---------- . It seems to have a problem in the second query when i say WHERE MAKER_ID=$ID.
<?php $count++; setcookie("count", $count); ?>
<?php echo ($count . ($count == 1 ? "visit" : " visits")); echo(" <br>");
include ("pw.inc"); include ("functions.php3"); include ("info.inc");
$table="auto_makers";
$field_name="auto_maker";
function createSelect ( $field_name, $table, $Select = 0, $select_id="" ) { global $db_name;
$conn = db_connect($db_host,$db_user,$db_pass,$db_name); $query = "SELECT model_id, auto_maker FROM auto_makers"; $res= db_query($query,$conn);
printf("<select name=\"$field_name\">\n"); if ($Select == "0") { printf("<option \"\">Choose maker\n"); printf("<option \"\">--------\n");}
while ($row = db_fetch_array($res,$nr) ): $id = $row["model_id"]; $name = $row["auto_maker"]; if ($id == $select_id) { printf("<option SELECTED value=\"$id\">$name\n"); } else { printf("<option value=\"$id\">$name\n"); } endwhile; printf("</select>\n");
###########################################################
$table2="auto_models"; $field_name2="model";
echo ("<br>"); echo ("<br>");
function createSelect2 ( $field_name2, $table2, $Select = 0, $select_id="" ) { global $db_name;
$conn = db_connect($db_host,$db_user,$db_pass,$db_name); $query = "SELECT maker_id, model FROM auto_models where maker_id='$id' "; $res= db_query($query,$conn);
printf("<select name=\"$field_name2\">\n"); if ($Select == "0") { printf("<option \"\">Choose Model"); printf("<option \"\">--------\n");}
while ($row= db_fetch_array($res,$nr) ): $maker_id = $row["maker_id"]; $field_name2 = $row["model"]; if ($maker_id == $select_id) { printf("<option SELECTED value=\"$maker_id\">$name\n"); } else { printf("<option value=\"$maker_id\">$field_name2\n"); } endwhile; printf("</select>\n");
}}
?>
<?php
#createSelect("FirstName","namedbase",1);
createSelect("auto_maker","");
createSelect2("model","");
?>
|
|