displaying php results

Discussion in 'PHP' started by adamk1, Sep 25, 2007.

  1. #1
    I have a problem getting my head around having multiple returns in a query and formatting them so they are limited to say 12 but are left to right 6 then below the same, basically what I am trying to do is re- develop http://playrandom.com which has a similar lay out to the previous version was not php / database driven.

    The problem which I am coming across is that it is all well and good having them displayed below each other as the html pattern is the same, but in this instance there are two different html tags e.g. ….. <td>blar</td><td>blar</td><td>blar</td> after every 6 there is a </tr> which would put the next set of result below.
     
    adamk1, Sep 25, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    $query = mysql_query("...") OR die(mysql_error());
    $rows = 0;
    
    echo '<table>
              <tr>';
    
    while ($row = mysql_fetch_assoc($query))
    {
         echo '<td>stuff here</td>' . "\n";
    
        if (++$rows % 6 == 0)
        {
            echo "</tr><tr>\n";
        }
    }
    
    echo '</tr>
        <table>';
    
    PHP:
     
    nico_swd, Sep 25, 2007 IP
  3. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nice...i done it with declaring a variable $i and up it and never came to me that I could indeed use the $rows value
     
    Edynas, Sep 25, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Note that I'm using 2 similar named variables. $row and $rows.

    $rows holds an increasing integer and $row the current row from the database.
     
    nico_swd, Sep 25, 2007 IP
  5. Edynas

    Edynas Peon

    Messages:
    796
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #5
    %6 means 6 or an increment of 6?
     
    Edynas, Sep 26, 2007 IP
  6. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #6
    Multiple of 6.

    % means modulus, the remainder when you divide a number by another

    eg.
    5/2 = 2.5 or 2 with a modulus of 1
    18/4 = 4.5 or 4 with a modulus of 2
     
    krt, Sep 26, 2007 IP