Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2005
    Posts
    326

    4 things per row

    I've wanted to know how to do this for a long time...

    How do you pull all values from a table and have them display for times in a row.

    Example:


    Entry1 Entry 2 Entry 3 Entry 4
    Entry 5 Entry 6 Entry 7 Entry 8

    etc.

  2. #2
    Join Date
    Nov 2005
    Location
    Palma de Mallorca, Spain
    Posts
    259
    How about creating a table, and then going through all your values?

    Your table should end like...
    <table border=1>
    <tr><td>Entry1</td><td>Entry2<td>Entry3</td><td>Entry4</td></tr>
    <tr><td>Entry5</td><td>Entry6<td>Entry7</td><td>Entry8</td></tr>
    </table>

    If you want specific code... just ask..

    Juan

  3. #3
    Join Date
    Dec 2005
    Posts
    326
    That wouldn't work... I'm trying to get it from a mysql database

  4. #4
    Join Date
    Oct 2005
    Location
    Norwich, Norfolk
    Posts
    33
    You can do

    PHP Code:
    <?php
    $array 
    mysql_fetch_array($sql_query);
    ?>
    <table width="100%" border="0" cellpadding="0">
        <?php foreach (array_chunk($array4) as $row) { ?>
        <tr>
            <?php foreach ($row as $item) { ?>
            <td align="center"><?=$item['name']?></td>
            <?php ?>
        </tr>
        <?php ?>
    </table>
    Last edited by ssj4gogeta; 01-03-2007 at 02:20 PM.

  5. #5
    PHP Code:

    $i 
    0;

    while(
    $row mysql_fetch_array($query))
    {
        if(
    $i == 0) echo '<td>';
       
        echo 
    $row['data'];

        if(
    $i == 3) { echo '</td>'$i 0;}
        
    $i++;

    That's how it's done.
    Dyslexics Have More Fnu

  6. #6
    Join Date
    Aug 2005
    Location
    UK
    Posts
    654
    Shouldn't they be 'tr's, and have 'td's around the $row['data']; that would just put four data's in one TD cell.

  7. #7
    Join Date
    Dec 2005
    Posts
    326
    it only shows one result. This is what I have:

    PHP Code:
    while ($grid mysql_fetch_array($get)) {
     
    if (
    $row == 0) {
    echo 
    '<tr>';
    echo 
    "<td>$grid[status]</td>";
    }
    if (
    $row == 4) { 
    echo 
    '</td></tr>'
    $row 0;
    }
    $row++;
     

    http://wuensche.ca/battleship

  8. #8
    Join Date
    Oct 2004
    Location
    Shimonoseki
    Posts
    2,101
    PHP Code:
    while ($grid mysql_fetch_array($get)) 
    {
        if (
    $row == 0
        {
           echo 
    '<tr>';
        }
     
        echo 
    "<td>".$grid["status"]."</td>";

        if (
    $row == 3
        { 
           echo 
    '</tr>'
           
    $row 0;
        }

        
    $row++;

    Closed for winter...

Posting Permissions

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