Reply
Trying to have PHP calculate SUM of something
Old 06-27-2008, 08:29 PM Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
PHP Code:
$getWonItems mysql_query("SELECT auctionid FROM probid_winners WHERE buyerid='$id'");
while (
$wonItems=mysql_fetch_array($getWonItems)) {
$mysql "SELECT SUM(winamount) AS total FROM probid_auctions WHERE id='$wonItems'";
$earned mysql_query($mysql) or die(mysql_error());
while(
$row mysql_fetch_array($earned)){
$total $row['total'];
}

I get a resource id #24 error

Any help is greatly appreciated!
MoForce is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-27-2008, 09:51 PM Re: Trying to have PHP calculate SUM of something
Extreme Talker

Posts: 235
Location: United States
The bug is likely in these two lines:

PHP Code:
while ($wonItems=mysql_fetch_array($getWonItems)) {
$mysql "SELECT SUM(winamount) AS total FROM probid_auctions WHERE id='$wonItems'"
$wonItems=mysql_fetch_array($getWonItems) sets $wonItems to be an array. In the next line, you are trying a "WHERE id='$wonItems', but you can't use an array like that in a SQL error.

Hope that helps.
frost is offline
Reply With Quote
View Public Profile
 
Old 06-27-2008, 11:42 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
Yeah, I figured that's what it would be. Thanks for verifying that.

Anyone have any suggestions on how I could get this to work?
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-27-2008, 11:52 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
ok so I realized a silly error, but it didn't completely solve the problem...

PHP Code:
$getWonItems mysql_query("SELECT auctionid FROM probid_winners WHERE buyerid='$id'");
while (
$wonItems=mysql_fetch_array($getWonItems)) {
$mysql "SELECT SUM(winamount) AS total FROM probid_auctions WHERE id='".$wonItems['auctionid']."'";
$earned mysql_query($mysql) or die(mysql_error());
while(
$row mysql_fetch_array($earned)){
$total $row['total'];
}

The bolded part is what I changed. Ok so now.... the mysql_query on the first line does output multiple "auctionid"s which is perfect. The problem comes up on the 3rd line I believe because only 1 ".$wonItems['auctionid'] is used.

Last edited by MoForce : 06-28-2008 at 12:00 AM.
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 12:23 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
any ideas for the /\ post?
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 08:54 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
sorry, but I still need some help with this... so I had to bump it
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 10:00 PM Re: Trying to have PHP calculate SUM of something
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,320
Name: Keith Marshall
Location: West Hartford, CT
Are you still getting mysql errors?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 11:39 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
I'm not getting any errors now, but it's not doing what I want it to... well not entirely anyway.

refer to post #4
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-29-2008, 12:23 PM Re: Trying to have PHP calculate SUM of something
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,320
Name: Keith Marshall
Location: West Hartford, CT
PHP Code:
// Declare value of total
$total 0;
// Start loop
$getWonItems mysql_query("SELECT auctionid FROM probid_winners WHERE buyerid = '$id'");
while (
$wonItems mysql_fetch_array($getWonItems))
{
  
$getEarned mysql_query("SELECT SUM(winamount) AS total FROM probid_auctions WHERE id = '" $wonItems['auctionid'] . "'");
  
$earned mysql_fetch_array($getEarned);
  
  
// Add total
  
$total += $earned['total'];

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-29-2008, 10:21 PM Re: Trying to have PHP calculate SUM of something
Experienced Talker

Posts: 35
Name: Jack Shalt
Genius! Worked like a charm! I would have never thought of that!

Thanks!
MoForce is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Trying to have PHP calculate SUM of something
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 5.15002 seconds with 12 queries