alexmark Posted July 16, 2012 Share Posted July 16, 2012 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. 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. The code I am using is as follows. <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='1'"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['model'] ?></option> <?php } ?> </select> <!--<input name="formmodel" type="text" value="<?php echo $varmodel;?>" size="60" maxlength="100" />--> </td> I seem to be makeing a mess of this. I would like to thank everyone who looks at this for there help. Quote Link to comment https://forums.phpfreaks.com/topic/265792-pass-information-from-selection-in-form-when-calling-from-db/ Share on other sites More sharing options...
alexmark Posted July 16, 2012 Author Share Posted July 16, 2012 Sorry I posted teh code backwards <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='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='formmodel'>Model: </td> <td> <select name="formmodel" id="formmodel"> <?php $sql="SELECT id,model FROM model WHERE year='1'"; $result =mysql_query($sql); while ($data=mysql_fetch_assoc($result)){ ?> <option value ="<?php echo $data['id'] ?>" ><?php echo $data['model'] ?></option> <?php } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/265792-pass-information-from-selection-in-form-when-calling-from-db/#findComment-1361995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.