Jump to content

how to multiply(or sum) the dropdown box value that trieved from mysql database


wangtian

Recommended Posts

hi. I am stuck on the dropdown box value calculation. anyone can help me on this problem ? I appreciate it.

 

I have two dropdown boxes on my webpage, and the values that in the dropdown boxes are retrived from the mysql database.

 

dropdown box "A" displays two differnt values, which are "Chassise_Name" and "Chassise_price", and The dropdown box "B" displays the quantity of the item.

 

    Dropdown box "A"                                Dropdown box "B"

SuperServer 7036A-T(Black) $90                      3

 

 

"Superserver 7036A-T(Black)" is retrieved from the Chassis_Name ;

"$90" is retrieved from the chassis_Price;

"3" is retrieved from the Quantity in other table.

 

 

Question:

 

how can I take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"?

 

Here is my code:

 

 

 

echo "<table border='1'>";
echo "<tr><td>";

$result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") 
or die(mysql_error());  
echo '<select name="Chassis" onChange="change()">'; 
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo '<option Name="Chassis">',$row['Chassis_Name'],'    ',$row['Chassis_Price'],' ','</option>'; 
} 
echo '</select>';

echo "</td>";






echo "<td>";

$result= mysql_query("SELECT Number FROM Quantity") 
or die(mysql_error());  
echo '<select name="Quantity" Value="Quantity" onChange="change()" >'; 

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result)) {
// Print out the contents of each row into a table

echo '<option Name="Quantity">',$row['Number'],'</option>'; 
} 
echo '</select>';




echo "</td></tr>";
echo "</table>";


?>

Link to comment
Share on other sites

take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"?

When? When do you want to do that? You can't do it when you're displaying the page because the user hasn't picked anything yet, so your choices are:

a) When they pick something (from both dropdowns) but before they submit the form.

b) When they submit the form, probably on some kind of confirmation page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.