-
SitePoint Enthusiast
passing SUM() from mysql to PHP
my sql query returns the following list of datas
-------------------------
name SUM(marks)
------------------------
andy 561
jimmy 432
vic 665
ken 421
and i wish to pass these data to PHP program to be displayed in <TABLE>
function disp_mark($res){
while($row = mysql_fetch_array($res)){
print("<TR>\n");
print("<TD>".$row[name]."</td>\n");
print("<TD>".$row[SUM(marks)]."</td>\n");
print("</tr>\n");
}
}
it seems that i cant use $row[SUM(marks)]
Fatal error: Call to undefined function: sum()
so, what is the name of the column then?
how should i fix this?
thanks
-
quote it
$row["SUM(marks)"]
or use numeric indices
$row[1]
or mysql aliases
"SELECT SUM(...) as mysum"
...
$row["mysum"]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks