Returning results from MySQL

Hi all

I am working on a project and I can not seem to get this right no mater what I do.

I have 3 tables in db, year, manufacturer_id and models

I would like to display makes and models based on requests made by user. I.e., if a user selects Make as Ford and then Year as 1942 the Model should return a list of all models produced in that year. However it does not work can some one tell me where I am going wrong please.

[php]


Make:
<?php $sql="SELECT id,manufacturer FROM manufacturer"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <?php echo $data['manufacturer'] ?> <?php } ?> Year: <?php $sql="SELECT id,year FROM year"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <?php echo $data['year'] ?> <?php } ?>


Model:


<?php
$sql=“SELECT id,model FROM model WHERE year_id=‘1’”;
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<?php echo $data['model'] ?>
<?php } ?>[/php]

My data bases tables are set up as follows.

manufacturer
2 columns id (which is unique) and manufacturer

year
2 columns id (which is unique) and year

model
4 columns id (which is unique) year (which corresponds to year id table) manufacturer_id (which corresponds to manufactures id table) and model

[php]
$sql=“SELECT id,model FROM model WHERE year_id=‘1’”;
[/php]

This year_id=‘1’ shouldn’t have the single quotes around 1. It’s an integer as it’s an ID.

What is your code returning might help us look in the right place.

That is basicaly all the code. It just makes a drop down box for each selection in teh form.

if changing that fixed it hit solve so i know. Otherwise, goto the page the script should be loading, and see if any errors are returned. If we know what is actually sent we can track errors down easier.

There are no errors and the removel of the inverted comms did not change anything.

is the form meant to change as soon as a user selects or refresh and load from their options?

Yes it pulls the info from teh db as soon as teh user selects the info. It is selecting the info but instead of just returning the models for the year selected it returns them all.

you need JQUERY or something to do dynamic page updating in that case.

But everything works as it should it just will not return the models by the correct year. It lists all models for all years. It should only give the models listed for the year chosen.

Sponsor our Newsletter | Privacy Policy | Terms of Service