PHP Programming > Beginners - Learning PHP
Returning results from MySQL
Alexmark:
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 Code: ---<tr>
<td align="right" label for='formmake'>Make: </td>
<td><select name="formmake" id="formmake" onchange="return populateModel(this.value);">
<?php
$sql="SELECT id,manufacturer FROM manufacturer";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['id'] ?>" ><?php echo $data['manufacturer'] ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td align="right" label for='formyear'>Year: </td>
<td><select name="formyear">
<?php
$sql="SELECT id,year FROM year";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['id'] ?>" ><?php echo $data['year'] ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td align="right" label for='formmodel'>Model: </td>
<td>
<select name="formmodel" id="formmodel">
<?php
$sql="SELECT id,model FROM model WHERE year_id='1'";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option value ="<?php echo $data['id'] ?>" ><?php echo $data['model'] ?></option>
<?php } ?>
--- End code ---
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
RaythXC:
--- PHP Code: ---
$sql="SELECT id,model FROM model WHERE year_id='1'";
--- End code ---
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.
Alexmark:
That is basicaly all the code. It just makes a drop down box for each selection in teh form.
RaythXC:
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.
Alexmark:
There are no errors and the removel of the inverted comms did not change anything.
Navigation
[0] Message Index
[#] Next page
Go to full version