Results 1 to 7 of 7

Thread: Help displaying data in four columns?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Exclamation Help displaying data in four columns?

    I have 28 rows of data, i know how to display the data.

    The problem is that it lists the data in one column, I would like to display the 28 items within FOUR columns, equally.

    In the future I'll have more than 28 rows...

    data data data data
    data data data data
    data data data data
    data data data data

    Again, i would like the coulumns to contain the same amount of items, (unless it's an odd number of course)

    Thanks!
    Last edited by erbio; Jul 15th, 2007 at 02:48 PM.

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Re: Help displaying data in four columns?

    Code:
    $query = "SELECT * FROM recent"; 
     $result = mysql_query($query) or die(mysql_error());
     $num_rows = mysql_num_rows($result);	
    
     echo ceil($num_rows/4);
    the echo displays 7

    I just need to know how to put this data in FOUR columns, equally (unless odd of course)

    Anyone?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Re: Help displaying data in four columns?

    ????.............................

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help displaying data in four columns?

    Are you displaying this using text or HTML or what?


    Also, please don't keep bumping your thread, especially not at such short intervals.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    395

    Re: Help displaying data in four columns?

    Quote Originally Posted by penagate
    Are you displaying this using text or HTML or what?


    Also, please don't keep bumping your thread, especially not at such short intervals.
    I'm displaying the content with text and html.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Help displaying data in four columns?

    something like this? some old script I had lying around (in this case, it's 5 columns, rather than 4).
    PHP Code:
    <table border="1">
    <?php
      $pictures 
    = array("picture1""picture2""picture3""picture4""picture5""picture6""picture7");
      
    $ii 0//index for the row
      
    $cols 5//number of columns in each row
      
    $ncol true//whether or not to make a new column
      
    for($i 0$i <= count($pictures) - 1$i++){
        
    $ii++;

        
    //end a row?
        
    if($ii $cols){
          
    $ii 0//reset row index
          
    echo '</tr>' "\n";
          
    $ncol true;
        }

        
    //start a new row?
        
    if($ncol == true){
          
    $ncol false;
          echo 
    '<tr>' "\n";
        }

        
    //display image
        
    echo '  <td>' $pictures[$i] . '</td>' "\n";

        
    //is the table finished?
        
    if($i == count($pictures) - 1){
          
    //finish filling the column if we need to
          
    if($ii $cols){
            for(
    $j $ii$j $cols 1$j++){
              echo 
    '  <td>&nbsp;</td>' "\n";
            }
          }
          echo 
    '</tr>' "\n";
        }
      }
    ?>
    </table>
    working example of this code is here, still not sure if that's what you're looking for or not. if it is what you're looking for, it can easily be changed to work with a while() loop with mysql results rather than a for() loop with an array.

  7. #7
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Help displaying data in four columns?

    PHP Code:
    <table style="width: 100%;">
    <tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
    <?php
        $col 
    0;
        
    $query mysql_query("SELECT * FROM whatever WHERE whatever1 = whatever2");
        while(
    $row mysql_fetch_array($query)) {
            switch(
    $col) {
                case 
    0:
                    echo 
    '<tr><td>'.$row[$col].'</td>';
                    
    $col++;
                    break;
                case 
    3:
                    echo 
    '<td>'.$row[$col].'</td></tr>';
                    
    $col 0;
                    break;
                default:
                    echo 
    '<td>'.$row[$col].'</td>';
                    
    $col++;
                    break;
            }
        }
    ?>
    </table>
    Hope that helps
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

Posting Permissions

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



Click Here to Expand Forum to Full Width