SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Resource id #6 ????????? what is this headache

    i used this line in mysql with php to calculate the sum of a row ...


    $sum=mysql_query("select SUM(score) from username where optionno = correct");

    echo $sum;




    now this gives output Resource id #6

    what on earth does that mean please help people...i am new and learning and i wanna solve this ...how do i do with the script??

  2. #2
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change your code to the following:

    PHP Code:
    $sum mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = correct"));
    echo 
    $sum[0]; 

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BUT WHY DOES that give that error is that an error?

  4. #4
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats not an error it simply tells you what the variable holds, in this case its a resource id, much like a handle.

    also, your query should put strings in quotes:
    Code:
    $sum = mysql_fetch_array(mysql_query("SELECT SUM(score) FROM username WHERE optionno = 'correct'"));
    echo $sum[0];

  5. #5
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigduke
    also, your query should put strings in quotes:
    No, the way I posted it is correct because that is not a string it is a field in the table.

  6. #6
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, he is correct. This part:

    WHERE optionno = 'correct'"

    Does need the quotes as you are testing for the string 'correct'.

  7. #7
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I already talked to ranjitcool over PM and he told me that correct was a field in his table.

  8. #8
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mmm, perhaps a better naming convention is in order!


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
  •