SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to display the number of times during a mySQL fetch loop...

    PHP Code:

    while($row mysql_fetch_array($result))
    {
     
    $row[xxx]

    But I don't want to use $num++

    Do you know the code necessary to do so?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can find out how many rows there are in the result set.

    $numRows = mysql_num_rows($result);

    does that help?

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not exactly, I want a command that shows the row # during a mySQL fetch... not the total rows retreived

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, so you want to count through the loop where you fetch rows from the result set? Or am I not understanding something. Because incrementing a counter is the only way I know how to do this. Eg:
    PHP Code:
    $num 1;
    while(
    $row*=*mysql_fetch_array($result))
    {
    echo "This is row number $num";
       
    $num++;


  5. #5
    SitePoint Zealot
    Join Date
    Feb 2001
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I have limited the result from 30 to 120, $num will start with 1 every time.

    I need that command because I have to break a result into several pages...but all the rows are numbered.

  6. #6
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, for example if you want to display records from 30 through to 120 you could do something like this:
    PHP Code:
    $offset 30;
    $limit 90;
    $num $offset 1;

    $sql "SELECT * FROM tableName LIMIT $offset$limit";
    $result mysql_query($sql);
    while ( 
    $row mysql_fetch_array($result) {
       
    // print out the values, $num will tell you which record you have
       
    $num++;



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
  •