开发者

How to print data in a table from mysql

I want to extract the last eight entries from my database and print them into a two columns tab开发者_C百科le 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>';  


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜