views:

37

answers:

1

hello,

i want to extract the last eight entries from my database and print them into a 2 columns table!like this:

|1|2|
|3|4|
|5|6|
|7|8|

is that possible?

this is my code:

$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect(); 

    $sql = "SELECT ID, movieno
            FROM movies
            ORDER BY ID DESC
            LIMIT 8 ";

    $rows = $db->query($sql);

    print '<table width="307" border="0" cellspacing="5" cellpadding="4">';
    while ($record = $db->fetch_array($rows)) {
        $vidaidi = $record['movieno'];
        print <<<END
        <tr>
            <td>
                <a href="http://www.dadadada.com/watch?v=$vidaidi" target="_blank">

                <img src="http://img.dadadada.com/vi/$vidaidi/1.jpg" width="123" height="80"></a>   
            </td> 
        </tr>
    END;
    }
    print '</table>';  
A: 

Yes it's possible.

<table border=1><tr>
<?
$count = 0;
$max = 4;
while(your loop){
 $count++;
echo '<td>'.$count.' record stuff </td>';

if($count >= $max){
  //reset counter
   $count = 0;
  //end and restart
   echo '</tr><tr>';
 }

}
?>
</tr></table>
Pentium10
i get 4 columns and 2 rows
robertdd
aaaa, i get it ;) thanks
robertdd
:) read the code, there is a variable that holds the max items is set to 4, put there 8 or as many as you want.
Pentium10