SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I select the data from a single cell?

    Now that I have selecting the ID working (thanks sitepoint forums!) I have a new problem.

    I want to determine whether the data in a single cell (the 2nd column in the last row) is either 'on' or 'off' - previously successfully set by me.

    This is the code I have but the "mysql_result" line produces the following error:

    Warning: mysql_result(): Unable to jump to row 20 on MySQL result index 5 in /var/www/vhosts/sawebdev.ca/httpdocs/salsa/test.php on line 30

    When I echo $result I get "$result Resource id #5" - which I presume is "index 5" - what is that? The row count is correct (20) and the field I am trying to get the data from ('session') is the 2nd one. I don't understand why it's "unable" to jump to row 20 when there are, in fact 20 rows at this point.

    Here's the code:


    //get last row of table
    $sql = "SELECT COUNT(*) FROM congress";
    $rowsresult = mysql_query($sql);
    list($numRows) = mysql_fetch_row($rowsresult);
    echo '$numRows ' . $numRows . "<br>"; //the number of rows in your table

    //select 'session' column data
    $query = "SELECT session FROM congress";
    $result = mysql_query($query) or die(mysql_error());
    echo '$result ' . $result . "<br>";

    //put data of last 'session' column into $session
    //THIS IS CODE THAT PRODUCES THE ERROR
    $session = mysql_result($result,$numRows) or die(mysql_error());

    Thanks
    Charles

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    why are you retrieving 20 rows, just to look at the last row?

    also, there is no second column in the last row; your query only retrieves one column!

  3. #3
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know why I'm retrieving 20 rows to look at the last row - that's the code I was given when I asked how do I find the last row.

    'congress' is the name of the table and 'session' is the name of the column I'm trying to retrieve. I thought I could directly query that one column.

  4. #4
    SitePoint Zealot glowdot's Avatar
    Join Date
    Jun 2007
    Location
    Santa Monica, CA
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Someone gave you that code? Never listen to them again

    PHP Code:
    //get last row of table
    $sql "SELECT COUNT(*) FROM congress";
    $result mysql_query($sql);
    $numRows mysql_result($result,0);
    echo 
    'Rows: ' $numRows "<br>"//the number of rows in your table

    //select 'session' column data
    $query "SELECT session FROM congress LIMIT ".($numRows-1).",1";
    $result mysql_query($query) or die(mysql_error());
    $lastSession mysql_result($result0);
    echo 
    'lastSession: ' $lastSession "<br>"
    Advertise on Glowfoto
    banners as low as $25/month, text ads $10/month
    Share 10 million impressions per month!

  5. #5
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I think that's working now (initial test did anyway). That "someone" posted it on this forum in my last question. Guess you can't trust all the code you get in forums

  6. #6
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    i'm still uncomfortable with that code. why do you want the "last" row in the table? and how do you define "last"?

  7. #7
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm continuing this post but posted my next problem as a new question:
    http://www.sitepoint.com/forums/show...17#post3468917


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
  •