the_oliver Posted May 31, 2007 Share Posted May 31, 2007 Hello, Im trying to get some data from a database and then add all of the entries in each columb to get the total for each columb. I tried it with the following code but got the error: Warning: Invalid argument supplied for foreach() Thanks for any help! // Calculate the total number of tickets sold and pitches required $query1 = "SELECT tickets,pitch FROM t_order_numbers WHERE paypal_confirmed = 'true'"; $t_totals = pg_query($pg_connection, $query1); $t_data = pg_fetch_array($t_totals); $t_holder = 0; // Holder for the finnal ticket total (paid for) $t_holder2 = 0; // Holder for the finnal pitch total required foreach ( $t_data['tickets'] as $temp ) { $store = $t_holder; $t_holder = $store + $temp; } foreach ( $t_data['pitches'] as $temp2 ) { $store2 = $t_holder2; $t_holder2 = $store2 + $temp2; } Quote Link to comment https://forums.phpfreaks.com/topic/53798-using-an-array/ Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 // Calculate the total number of tickets sold and pitches required $query1 = "SELECT tickets,pitch FROM t_order_numbers WHERE paypal_confirmed = 'true'"; $t_totals = pg_query($pg_connection, $query1); //$t_data = pg_fetch_array($t_totals); $t_holder = 0; // Holder for the finnal ticket total (paid for) $t_holder2 = 0; // Holder for the finnal pitch total required while ($t_data = pg_fetch_array($t_totals)) { $store = $t_holder; $t_holder = $store + $t_data['tickets'] ; $store2 = $t_holder2; $t_holder2 = $store2 + $t_data['pitches']; } try that Quote Link to comment https://forums.phpfreaks.com/topic/53798-using-an-array/#findComment-265903 Share on other sites More sharing options...
the_oliver Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks. As stage further! I tried the code below. Strange thig was that both $t_holder and $t_holder2 came out as 6 The data returned from the query was: tickets | pitch ---------+------- 1 | 2 1 | 0 1 | 0 1 | 1 1 | 0 1 | 0 2 | 0 1 | 0 1 | 1 1 | 1 (10 rows) // Calculate the total number of tickets sold and pitches required $query1 = "SELECT tickets,pitch FROM t_order_numbers WHERE paypal_confirmed = 'true'"; $t_totals = pg_query($pg_connection, $query1); $t_data = pg_fetch_array($t_totals); $t_holder = 0; // Holder for the finnal ticket total (paid for) $t_holder2 = 0; // Holder for the finnal pitch total required foreach ( $t_data as $temp ) { $store = $t_holder; $t_holder = $store + $temp['tickets'] ; $store2 = $t_holder2; $t_holder2 = $store2 + $temp['pitches']; } Quote Link to comment https://forums.phpfreaks.com/topic/53798-using-an-array/#findComment-265907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.