Jump to content

using an array


the_oliver

Recommended Posts

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;

}

Link to comment
https://forums.phpfreaks.com/topic/53798-using-an-array/
Share on other sites

// 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

Link to comment
https://forums.phpfreaks.com/topic/53798-using-an-array/#findComment-265903
Share on other sites

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'];
}

Link to comment
https://forums.phpfreaks.com/topic/53798-using-an-array/#findComment-265907
Share on other sites

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.