0

Say I have two drop down boxes, and I have two columns then after I select the two columns that pulls from the stock tables to give me a total.. Whats the best way or does anyone have an example?

Ex Boxes - Yellow box - Red box = All the yellow and red boxes in stock ...

ex of a table boxes -

yellow box red box - 6 in stock

yellow box pink box - 7 in stock

yellow box red box 8 in stock

two drop downsthen = total
total <red > <yellow boxes> = 14 boxes

any suggestions or pointers would be greatly appreicated.

Thanks

5
Contributors
10
Replies
13
Views
5 Years
Discussion Span
Last Post by xbat
Featured Replies
  • ok.. so if Im following along with you right -> You're pulling stock numbers from a database. Those stock numbers are individually posted on your page for ordering purposes. If that is correct, you have two options. Do the math in the database `"SELECT col1, col2, (SELECT SUM(col1, col2)) as … Read More

1

ok.. so if Im following along with you right ->
You're pulling stock numbers from a database.
Those stock numbers are individually posted on your page for ordering purposes.

If that is correct, you have two options.

Do the math in the database
"SELECT col1, col2, (SELECT SUM(col1, col2)) as total FROM mytable WHERE boxcolor='whatever';"

Do the math after the database

while($data = mysql_fetch_object($result)) {
$total = $data->col1 + $data->col2;

}

Is that what you're looking for?

Ryan

Votes + Comments
I right now wanted to write something like this, but you're faster!
0

I'm not sure if i understand you but it think you need to do is fetch the datas from column of your database.

$sql= "SELECT yellowbox, redbox , SUM(yellowbox,redbox) as TOTAL from table_name where boxcolor = 'SELECTED COLOR'";

then do the PHP code:

while ($row =mysql_fetch_assoc($sql)){
$total = $row['TOTAL'];
// If this ain't going to work used this 
//$total = intval($row['yellowbox'] + $row['redbox']);
//Lets assume your input are all integer.
echo $total;
}

-Alex

0

If that is correct, you have two options.

Do the math in the database

Is that what you're

"SELECT col1, col2, (SELECT SUM(col1, col2)) as total FROM mytable WHERE boxcolor='whatever';"

Do the math after the database
$sql= "SELECT yellowbox, redbox , SUM(yellowbox,redbox) as TOTAL from table_name where boxcolor = 'SELECTED COLOR'";

then do the PHP code:

then do the PHP code:

> while ($row =mysql_fetch_assoc($sql)){
> $total = $row['TOTAL'];
> // If this ain't going to work used this
> //$total = intval($row['yellowbox'] + $row['redbox']);
> //Lets assume your input are all integer.
> echo $total;
> }

**Thank you.. but with this it wouldn't be dynamic. I need something where people can select what box color, then after selecting the box colors then it would total the amount of selected box colors through the database.
**

> $sql= "SELECT yellowbox, redbox , SUM(yellowbox,redbox) as TOTAL from table_name where boxcolor = 'SELECTED COLOR'";
> 
> then do the PHP code:
> 
>     while ($row =mysql_fetch_assoc($sql)){
>     $total = $row['TOTAL'];
>     // If this ain't going to work used this
>     //$total = intval($row['yellowbox'] + $row['redbox']);
>     //Lets assume your input are all integer.
>     echo $total;
>     }

thank you by with this it would only total yellowbox and redbox, I'm looking at drop down to select the colors, then it would calulate the total that is in stock of the colors selected. I was thinking I would be able to get away with php but I think I might have to do javascript.... my javascript is rusty.

Edited by xbat

0

This has confused the hell out of me.
Could you give an example of the dropdown contents and your table structure with a couple of datarows as an example?

0

If I have understood you correctly, then you need to retrieve the total stock value from the database for all boxes that match either the first, or second colour selected.

Without seeing your database schema, I cannot write an exact query, however hopefully the following will point you in the right direction.

// This assumes two valid colours have been selected
$colour_1 = 'red';
$colour_2 = 'yellow';

// Find and sum stock value for rows where colour is red or yellow
$sql = sprintf("SELECT SUM(`stock`) AS `stock` FROM `table` WHERE `colour` IN ('%s', '%s')", $colour_1, $colour_2);
0

diafol - Sorry.. yes now that I read it months later I was like man what was I writing... But Blocblue yes you are correct... Thats what i was looking for... Thank you..

I needed to add up all the different but matching itmes say for example I have a chair factory..

so I have the options of -

Here is my table -

Column 1 Leg color - Column 2 Seat Color - Column 3 chair handle color - Stock

brown - black - pink - 4
brown - white - pink - 5
brown - white - pink - 7
brown - black - yellow - 9

Now lets say I have a gaint database and I just want to add the totoal number for all brown white and pink witch will total - 12

Thats all I was trying to explain.

Thanks... I'm not sure if there is a better way of doing this.. but I was using drop down select menus.

0

Anyone? Even If I can do two that would be wonderful...

0

I figured this one out...Turns out I was just missing some basic where item = thing AND item = thing

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.