
June 20th, 2004
07:55 PM
Neverside Newbie
Status: Offline!
sum trouble
If got this query ("SELECT sum(comment_rating) AS total From comments WHERE link_name='affilate'") that works fine when I run it through phpmyadmin but I just can't echo it.
<?php
$query = "SELECT sum(comment_rating) AS total From comments WHERE link_name='affilate'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);
echo $row['total'];
?>
whats wrong?
___________________
Comming soon.....The Lord of The Links

June 20th, 2004
08:57 PM
what could you possibly want to know about me?
Status: Offline!
That's because mysql_fetch_row returns an enumerated array - if you
want to refer to the result by $row['total'] (rather than $row[0]) use
mysql_fetch_array instead.

June 20th, 2004
10:24 PM
Neverside Newbie
Status: Offline!
sabrina,
Thanks you've been a great help, now I can stop banging my head against the wall.
Cheers,
___________________
Comming soon.....The Lord of The Links

June 22nd, 2004
08:25 AM
thinking of something witty to put here
Status: Offline!
For retrieving a single value use mysql_result instead as it will work faster.
<?php
$sum = mysql_result($result, 0);
echo $sum;
?>

June 22nd, 2004
08:42 AM
Neverside Newbie
Status: Offline!
Radley,
Cheers
___________________
Comming soon.....The Lord of The Links

June 22nd, 2004
11:59 PM
always die on mysql_error() when you do a query, ALWAYS
___________________
Current Project: LivermoreMuscle.com
Sig Hosted by Motorspin

June 23rd, 2004
03:44 AM
Neverside Newbie
Status: Offline!
Originally posted by Adam
always die on mysql_error() when you do a query, ALWAYS
Cheers Adam
___________________
Comming soon.....The Lord of The Links