Jump to content

mysql reslut into an array and then math


Skewled

Recommended Posts

I looked into the php documentation but that stuff get's confusing at times, and right now I'm feeling a bit overwhelmed. So I'm putting together some data that I can follow in hopes that someone would be kind enough to explain how to place this information into an array and then how to apply math to that array.

 

Let's say I have the following:

 

My Mock Table:

table: test
rows: val1 val2 val3 val4 val5
data:  3    2    10    5   5
data:  5    3    30    20  15

 

// Do query stuff
$query = "SELECT * FROM test";
$data = mysqli_query($database, $query);

// Drop the results into $row
while ($row = mysqli_fetch_array($data)) {

// From here I'm confused as to how to place them into an array that I can then sort, add values, subtract values, and so fort...
$newarray[] = $row;

} // end while loop

Hello,

 

table: test
rows: val1 val2 val3 val4 val5 valid
data1:  3    2   10  200  15   3
data2:  5    3   30  120  15   3

 

I guess what I'd like to accomplish is:

 

val5 * 10 = $totalallowed (150)  -- I want to limit the sum of data1 and data2 to this number but have the highest val1 used first.

 

data2: val4(120) * val1(5) = $totalnumber (600)

data1: val4(30) * val1(3) = $totalnumber1 (90)

 

$maxtotal = 90 + 600 (690)

 

If I can do it in the query I tried using SUM, COUNT and all that but go way too confused.

 

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.