Jump to content

[SOLVED] How to echo the option value of a dropdown?


adrafa

Recommended Posts

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!

 

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];

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.