SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    ms
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    quote it

    $row["SUM(marks)"]

    or use numeric indices

    $row[1]

    or mysql aliases

    "SELECT SUM(...) as mysum"
    ...
    $row["mysum"]


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •