phpmysql problem

Discussion in 'PHP' started by izlik, Dec 28, 2010.

  1. #1
    Hello

    In the sql i have bellow it currently prints out the stuff from the database like this

    home 1
    home 2
    home 3

    but how can i insteed make it print it out in 3 lines each insted like this insteed ?

    home 1 home 2 home 3
    home 4 home 5 home 6

    $sql = '$sql = 'SELECT * FROM `homes` ORDER BY `homes`.`homes` ASC';
                     $r = $db->_sql($sql);
                    while ($row = $db->fetch_row($r)) {
                        $tpl->set('q_id', $row['id']);
                        $tpl->set('quote', $row['homes']);
                        print($tpl->fetch($tpl->tdir.'quote_block2.tpl'));
                    }
    
    PHP:
     
    izlik, Dec 28, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    Try something like this:

    
    $sql = '$sql = 'SELECT * FROM `homes` ORDER BY `homes`.`homes` ASC';
                     $r = $db->_sql($sql);
    $columns = 3;
    $column = 0;
    echo "<table>\n";
                    while ($row = $db->fetch_row($r)) {
                      if($column == 0){echo "\n<tr>";}
                        echo "\n\t<td>";
                        $tpl->set('q_id', $row['id']);
                        $tpl->set('quote', $row['homes']);
                        print($tpl->fetch($tpl->tdir.'quote_block2.tpl'));
                        echo "</td>";
                        if($column == $columns){
                                 echo "\n</tr>"; $column = 0;
                         }else{
                                 $column++;
                         }
                       
                    }
                   echo "\n</table>";
    
    Code (markup):
     
    shofstetter, Dec 28, 2010 IP
    izlik likes this.
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Thanks a lot for that m8 =)
     
    Last edited: Dec 29, 2010
    izlik, Dec 29, 2010 IP