SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying only part of a mysql result set..?

    If I have a mysql result set in $thisVar that contains say 100 rows...and what I want to do is to display the rows as fields of a table...but only for rows that are greater than x and less than y.

    When mysql results are gathered, does each row get an "id" number or something that could be used to tell if it's the 20th row or the 25th row that was returned?

    Thanks,

    Cranjled

  2. #2
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $startRow 20;
    $endRow 30;
    $i 0;
    $sel mysql_query ("SELECT fieldname FROM table");
    while (
    mysql_fetch_array($sel)) {
     if (
    $i $startRow && $i <= $endRow) {
      echo 
    $fet['fieldname'] . '<br />';
     }
     
    $i++;

    There is probably a better way to do that, but that should work too.

    - Trog

  3. #3
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that worked nicely.

  4. #4
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excellent! No prob.

  5. #5
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about this

    PHP Code:
       $start_row 19;
       
    $num_rows 10;
       
       
    $sql 'SELECT fieldname FROM table LIMIT ' $start_row ',' $num_rows;
       
    $result mysql_query($sql);
       while (
    $row mysql_fetch_assoc($result))
       {
         echo 
    $row['fieldname'] . '<br />';
       } 
    In this scenario, you need to know the starting row (rows start from 0) and the numebr of rows you require.

    For more info, look at http://dev.mysql.com/doc/mysql/en/SELECT.html

  6. #6
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to you too swdev.


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
  •