Page 2 of 2
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 7:56 am
by simonmlewis
Yes I did. Spent a lot of time checking it, but it's a style of code I have used a lot over the years, and am unfamiliar with other code.
Problem with the response was they were giving me very useful answers.... and then not really an answer at all, which is a little counter-productive.
I would personally say "have you checked this...".... I would say "try this in the code at this stage...".
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 8:20 am
by VladSun
I usually refuse to give people "copy-paste" solutions. You should know why I do this ...
You didn't even read what I posted - I said "Put sum() in the SELECT clause" and you ... you put it in the GROUP BY clause ...
I'm willing to help, but you are not willing to use it... I'm not a debugger, you know ...
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 8:32 am
by simonmlewis
Nope, you're moody.
Never mind.
I did try BOTH options actually, but neither worked for me.
Just need some help and guidance here. Sometimes someone needs the route to a destination, not just to be given a signpost and continue getting lost.
By the way, I have used maps!
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 9:09 am
by simonmlewis
An additional note: this code:
Code: Select all
$result = mysql_query ("
SELECT persondealing, estimate, SUM(total) AS amount_per_person FROM matterusersrights
INNER JOIN matterdata ON matterdata.clientcode = matterusersrights.clientcode
WHERE matterusersrights.userid = '" .$cookieid."' GROUP BY persondealing");
while ($row = mysql_fetch_assoc($result))
{
echo "<br/>
<b> $row->persondealing</b><br/>
$row->estimate<br/>";
echo $row['amount_per_person'];
}
mysql_free_result($result);
mysql_close($sqlconn);
Produces ONLY the sum of 'total', and doesn't echo anything else. I suspect it could be down toe fetch_assoc, as if I change assoc to object, it shows the name and estimate, but breaks at the $row[]; point.
ie. assoc works for the sum of total using the [] ,method. object works for the persondealing and estimate fields. But neither works for both.
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 9:13 am
by Mark Baker
Either
Code: Select all
while ($row = mysql_fetch_assoc($result)) {
echo $row['persondealing'];
echo $row['estimate'];
echo $row['amount_per_person'];
}
or
Code: Select all
while ($row = mysql_fetch_object($result)) {
echo $row->persondealing;
echo $row->estimate;
echo $row->amount_per_person;
}
but this isn't pick and mix
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Posted: Mon Jan 19, 2009 10:06 am
by simonmlewis
Fantastic - I think as you say it was pick'n'mix.... using two different styles of rendering the values.
Thank you very much for a descriptive response.

I knew there was someone out there.