boney alex Posted April 3, 2007 Share Posted April 3, 2007 Hi, I'm fairly new to PHP and I'm having difficulties displaying the MakeModelID for a row selected from a drop down menu I've populated from a table combining three attributes (Make, Model and Specification - for example Ford Transit LWB 350 HR). What I require is to capture in a variable, such as $MakeModelID, the ID for that record selected. <fieldset> <legend>Please select the Type of Van</legend> <?php $result = mysql_query("SELECT MakeModelID, Make, Model, Specification FROM MakeandModel ORDER BY Make, Model, Specification"); ?> <label for="branch">Type of Van:</label> <select name="vantype" STYLE="width: 220px" size="0"> <option selected value=""></option> <?php while ($row = mysql_fetch_array($result)) { echo "<option value=\"$row[MakeModelID]\">$row[Make] $row[Model] $row[specification]</option>\n"; } ?> </select><br> </fieldset> Any help would be much appreciated. Thanks! Alex Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/ Share on other sites More sharing options...
phoenixx5 Posted April 3, 2007 Share Posted April 3, 2007 It looks like you've forgotten to assign row values. for instance $MakeModelID = $row[x]; echo "<option value=\"$MakeModelID\" .......... Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220796 Share on other sites More sharing options...
boney alex Posted April 3, 2007 Author Share Posted April 3, 2007 do you mind explaining what code I've missed out phoenix? Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220798 Share on other sites More sharing options...
trq Posted April 3, 2007 Share Posted April 3, 2007 Complex variables should be surrounded by curly braces when within quotes. echo "<option value=\"{$row['MakeModelID']}\">{$row['Make']} {$row['Model']} {$row['Specification']}</option>\n"; Also note that non-numerical array indexes should always be surrounded by quotes. Does that help at all? I'm still note real sure what your question actually was. Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220800 Share on other sites More sharing options...
trq Posted April 3, 2007 Share Posted April 3, 2007 do you mind explaining what code I've missed out phoenix? You haven't missed anything except error handling. You should always check your query actually worked before trying to use the result. <fieldset> <legend>Please select the Type of Van</legend> <label for="branch">Type of Van:</label> <select name="vantype" STYLE="width: 220px" size="0"> <option selected value=""></option> <?php if ($result = mysql_query("SELECT MakeModelID, Make, Model, Specification FROM MakeandModel ORDER BY Make, Model, Specification")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { echo "<option value=\"{$row['MakeModelID']}\">{$row['Make']} {$row['Model']} {$row['Specification']}</option>\n"; } } } ?> </select><br> </fieldset> Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220805 Share on other sites More sharing options...
boney alex Posted April 3, 2007 Author Share Posted April 3, 2007 my code manages to produce the drop down as you can see by visiting: http://co-project.lboro.ac.uk/users/coajs/quoteandbook What I'm strugglin with is once a user selects a van type from the drop down list, how do I capture the MakeModelID for the option selected? Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220811 Share on other sites More sharing options...
trq Posted April 3, 2007 Share Posted April 3, 2007 Once your form has been submitted you will find it within $_POST['vantype']. Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220813 Share on other sites More sharing options...
boney alex Posted April 3, 2007 Author Share Posted April 3, 2007 Thanks thorpe! Your a legend! Got it sorted! Link to comment https://forums.phpfreaks.com/topic/45473-solved-problem-with-dynamic-drop-down-menu/#findComment-220829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.