mysql result question
Results 1 to 7 of 7

Thread: mysql result question

  1. #1
    Member
    Join Date
    Nov 2012
    Posts
    43

    mysql result question

    Hello, I would like to ask about mysql_result function.

    I have to supply 3 parameters inside. First a place where to look (usually a query where you grab data). The second one I dont understand. And the third one is the field from database, am I correct?

  2. #2
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    You should not use any of the mysql_* functions.
    They are long outdated and no longer recommended for use - use mysqli or PDO instead.
    Read more about choosing an API for MySQL.

    The second parameter of mysql_query() is the row number, starting with 0 (the first row).
    Last edited by traq; 11-25-2012 at 07:09 PM.

  3. #3
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,349
    First of all, I agree with traq: Stop Using the MySQL Extension!

    However:
    Quote Originally Posted by phpbuild12 View Post
    The second one I dont understand.
    Which part of the following description (taken from the PHP manual for mysql_result(), of course):
    Quote Originally Posted by PHP Manual
    The row number from the result that's being retrieved. Row numbers start at 0.
    don't you understand?

  4. #4
    Member
    Join Date
    Nov 2012
    Posts
    43
    Ohh so it means it will return ALL rows, but start at 0?

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,349
    It can return all rows if called repeatedly, sure. But if you're calling it more than once, then you should probably just be using one of the fetch_*() functions inside a while() loop instead.

  6. #6
    Senior Member traq's Avatar
    Join Date
    Jun 2011
    Location
    so.Cal
    Posts
    949
    Quote Originally Posted by phpbuild12 View Post
    Ohh so it means it will return ALL rows, but start at 0?
    No, it returns whatever field you ask for, from whatever row you ask for. If you pass "0" in the second parameter, it will read from the first row.

    As bradgrafelman says, you can loop though all the rows by calling the function repeatedly, but there are much better ways to do that.

  7. #7
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,349
    Quote Originally Posted by traq View Post
    you can loop though all the rows by calling the function repeatedly, but there are much better ways to do that.
    ... for example: mysqli_fetch_all()

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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