Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.