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...".
PHP/SQL GroupBy *and* sum total of Grouped Figure
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
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 ...
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 ...
There are 10 types of people in this world, those who understand binary and those who don't
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
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!
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!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
An additional note: this code:
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.
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);ie. assoc works for the sum of total using the [] ,method. object works for the persondealing and estimate fields. But neither works for both.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
Either
or
but this isn't pick and mix
Code: Select all
while ($row = mysql_fetch_assoc($result)) {
echo $row['persondealing'];
echo $row['estimate'];
echo $row['amount_per_person'];
}
Code: Select all
while ($row = mysql_fetch_object($result)) {
echo $row->persondealing;
echo $row->estimate;
echo $row->amount_per_person;
}
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: PHP/SQL GroupBy *and* sum total of Grouped Figure
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.
Thank you very much for a descriptive response.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.