Skewled Posted August 4, 2010 Share Posted August 4, 2010 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 Link to comment https://forums.phpfreaks.com/topic/209831-mysql-reslut-into-an-array-and-then-math/ Share on other sites More sharing options...
Pikachu2000 Posted August 4, 2010 Share Posted August 4, 2010 Depending what it is you're trying to do, you may be able to perform the operations in the query itself. Can you provide an example of the data and operations you want to perform? Link to comment https://forums.phpfreaks.com/topic/209831-mysql-reslut-into-an-array-and-then-math/#findComment-1095309 Share on other sites More sharing options...
Skewled Posted August 4, 2010 Author Share Posted August 4, 2010 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. Link to comment https://forums.phpfreaks.com/topic/209831-mysql-reslut-into-an-array-and-then-math/#findComment-1095317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.