Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2007
    Location
    US
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts

    Organizing database output.

    How do I format my data into a table?
    This sounds simple enough but I can't figure it out.

    You see I've got a lot of table space to use, but can't get the data to format into only a few table rows.
    The code I'm using now looks like this:
    PHP Code:
    $result1 mysql_query ('select * from friends where p_id="'.$user_id.'" order by uf_id desc limit '.$f_num.'') or dbError();  
    $fc =1;

          if(
    mysql_num_rows($result1))
          {

              while(
    $fr mysql_fetch_assoc($result1))
            {
            echo
    '    <tr>';
                echo 
    '<td '.getColor($fc).'><a class="usnav" href="'.$url.'/eldemonio/profiles/'.$fr['username'].'.php">'.$fr['username'].'</a></td>';
            echo
    '    </tr>';
            
    $fc++;
            }
          } 
    I'd like that code above too be able to out put that same variable about three times or so with in the same <tr> but I want it to be the next one in line after the first one.
    So it would end up like so:

    name1 / name2/ name3/

    Sure thats simple to do also, but how do i get it to create new row after the first three names?

    Hope I was clear enough for you guys to get what I mean, this ones kinda complicated for me.
    I need to find a book about all this stuff. God, thats gonna be one big book!

    http://www.gamezftw.com
    Play On!

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    while($fr mysql_fetch_assoc($result1)){
            if (
    $fc == 1) echo '    <tr>';

            
    // Removed this to make it easier to see
            
            
    if ($fc == 3){
                 echo 
    '    </tr>';
                 
    $fc 0;
            }
            
    $fc++;
    }
    if (
    $fc != 1) echo '    </tr>'

  • Users who have thanked Mwnciau for this post:

    Digicoder (10-31-2007)

  • #3
    New Coder
    Join Date
    Sep 2007
    Location
    US
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Thanks very much. That did the job just right.
    I need to find a book about all this stuff. God, thats gonna be one big book!

    http://www.gamezftw.com
    Play On!


  •  

    Posting Permissions

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