Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Trying to have PHP calculate SUM of something
Old 06-27-2008, 09:29 PM Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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
 
 
Register now for full access!
Old 06-27-2008, 10:51 PM Re: Trying to have PHP calculate SUM of something
Extreme Talker

Posts: 238
Location: United States
Trades: 0
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-28-2008, 12:42 AM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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-28-2008, 12:52 AM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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 01:00 AM..
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 01:23 PM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
any ideas for the /\ post?
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 09:54 PM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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, 11:00 PM Re: Trying to have PHP calculate SUM of something
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
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-29-2008, 12:39 AM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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, 01:23 PM Re: Trying to have PHP calculate SUM of something
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
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, 11:21 PM Re: Trying to have PHP calculate SUM of something
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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 0.49688 seconds with 12 queries