SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looing through recordset question

    What I want to do is output the first 5 records of 10 from a database query and then modify the output slightly for the next 5. What's the best way to do it? At the moment, I've got:

    PHP Code:
       if(is_array($var)) {
           foreach (
    $var as $v) {
              
    // do stuff
              
    }

    $var is created from the database query. Can I do this using the same query and modifying the loop or do I need two separate queries?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Anything you can't do while fetching the dataset? Like:

    Code php:
    //...
     
    $c=floor(mysql_num_rows($r)/2);
     
    $i=0;
     
    while($row=mysql_fetch_array($r)){
      if($i++<=$c){
        echo '<div class="first">'.$row['f1'].'</div>';
      }else{
        echo '<div class="second">'.$row['f2'].'</div>';
      }
    }
    Saul

  3. #3
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That set me on the right track. Thanks


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
  •