SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast hartmurmur's Avatar
    Join Date
    Aug 2001
    Location
    Chicago
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pull field contents from non-consecutive rows

    I have a mysql query that returns a large number of results. Is there a PHP/MySQL function that can return the contents of every nth row (where n is a $variable)?

    Please provide simple examples if possible.

    Thanks!

  2. #2
    SitePoint Zealot Ace Nova's Avatar
    Join Date
    Aug 2000
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you try to make a loop and have it count up to nth row and display it, and reset until there are no more rows


    $curnum = 1;
    $numfreq = 10;
    while ($something = mysql_fetch_array($something2)) {

    if ($curnum == $numfreq) {
    //print out the data, put everything you want to do with it
    $curnum = 1;
    } else {
    //increases by 1
    $curnum++;
    }

    }
    Ace Nova
    Football Man
    InternetSprite.Com - Coming Soon!

  3. #3
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The last example would only display the tenth result, not every ten results. Try this:

    PHP Code:
    $n "3";
    $i 1;
    $sql "SELECT * FROM $table";
    $result mysql_query($sql);
    while(
    $row mysql_fetch_array($result)){
        
    $name $row['name'];
        
    $date $row['date'];
        if(
    $i $n == 0){
            echo(
    "$name Signed Up $date\n");
        }
        
    $i++;

    That wil display every 3 results, 3,6,9,12,15,18,21....
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  4. #4
    SitePoint Zealot Ace Nova's Avatar
    Join Date
    Aug 2000
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ($curnum == $numfreq) {
    //print out the data, put everything you want to do with it
    $curnum = 1;
    It will print every ten results, i reset the var $curnum after it has reached 10
    Ace Nova
    Football Man
    InternetSprite.Com - Coming Soon!

  5. #5
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    excuse me for not reading closer...
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services


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
  •