adrafa Posted December 17, 2008 Share Posted December 17, 2008 Hi there! Here is what I need. I have a table with two columns (outlet_rate, sub_class) I'm populating sub_class in a dropdown for the user to select, once the user select the sub_class I need to echo in the action page the sub_class and the outlet_rate. I can only seem to echo the price. What I'm I missing? Here is part of my code: <form action="discount.php" method="post" name="tender" id="tenderForm"> <?php mysql_connect("localhost", "*****", "******") or die(mysql_error()); mysql_select_db("vema") or die(mysql_error()); $query="SELECT * FROM outlets WHERE outlet_rate >0 AND menu_level = 2"; $result = mysql_query($query); echo '<select name="outlet_rate">'; while($nt=mysql_fetch_array($result)){ echo "<option value=\"$nt[outlet_rate]\">$nt[sub_class]</option>\n"; echo outlet_rate; } echo '</select>'; ?> <input type="submit" value="Apply"> </form> In discount.php I do <?php echo $_POST['outlet_rate'];?> but where is the value of sub_class? How do I echo sub_class? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/ Share on other sites More sharing options...
trq Posted December 17, 2008 Share Posted December 17, 2008 Only the value attribute will be sent to the action page. You could store both the sub_class and the outlet_rate within the value attribute seperated by a delimeter or something. Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717850 Share on other sites More sharing options...
phpian Posted December 17, 2008 Share Posted December 17, 2008 I don't know if you can. what does your data look like? it seems strange to me that you would want the value of the option to be outlet_rate when you want to find out what sub_class was selected. Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717854 Share on other sites More sharing options...
adrafa Posted December 17, 2008 Author Share Posted December 17, 2008 thorpe, how to do do that? How do I store both values? Thanks! Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717856 Share on other sites More sharing options...
adrafa Posted December 17, 2008 Author Share Posted December 17, 2008 thanks for your reply phpian I want to know both, what the user selects and the rate of the outlet associated with the user selection Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717861 Share on other sites More sharing options...
trq Posted December 17, 2008 Share Posted December 17, 2008 How do I store both values? echo "<option value=\"{$nt['outlet_rate']},{$nt['sub_class']}</\">{$nt['sub_class']}</option>\n"; Then on your action page you would explode $_POST['outlet_rate'] to get both values. eg; $vals = explode(',', $_POST['outlet_rate']); $outlet_rate = $vals[0]; $sub_class = $vals[1]; Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717863 Share on other sites More sharing options...
adrafa Posted December 17, 2008 Author Share Posted December 17, 2008 thorpe you are the man!!! I kind of figure it out after your first answer, but you make it even clearer with your reply. I will continue to come to this forum for quick and expert answers Thanks again!!! Link to comment https://forums.phpfreaks.com/topic/137383-solved-how-to-echo-the-option-value-of-a-dropdown/#findComment-717868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.