新来的这个董事会,但到目前为止很喜欢它:)
我目前正在帮助我的一个朋友重做她的个人网站,并且我正在为一张桌子的逻辑撞墙。
该表应该在由 4 个列/单元格/TDs pr 行组成的表中显示最新消息(仅此而已) - 类似于这样的内容: http ://screencast.com/t/Rh39oh6ms0OL
所以基本上我有一个 SQL 查询,它从新闻表中选择日期、缩略图和标题(按 id desc 排序,所以我首先得到最新的)。
我已经做了一些逻辑(如您在下面的代码中所见),但它只会导致表格的第一行显示。有谁能让我回到正确的轨道上吗?将不胜感激。
<table>
<?php
//PHP code used for building HTML table showing news-resumes
//Written by: Jesper Flindt
//Date: 2012.07.30
//Version: 1.0
//Getting data from MySQL database
$query = "select date, thumbnail, headline from news order by id desc";
$result = mysql_query($query) or die("Connection Error:" . mysql_error());
//Setting variables
$i = 0;
$p = 0;
//Starting row in table
print('<tr>');
//Looping through the resultset
while($row = mysql_fetch_assoc($result))
{
//Limit row to 4 cells (TDs)
if($i < 4)
{
//Display the date of the news as well as its thumbnail
print('<td><div style="padding-left:8px;"><b>Tilføjet d. '.$row['date'].'</b></div><div class="news_thumbframe"><img src="./upload/'.$row['thumbnail'].'" alt=""/></div></td>');
$i++;
$p++;
}
//If row is 4 cells wide, start new row
else if($i % 4 == 0)
{
print('</tr><tr>');
$i++;
$p++;
}
//Every second row should display the news headline as well as a "Read More" link ("Læs mere" in danish)
else if($i % 4 != 0 || $p % 4 == 0)
{
print('<td width="215" valign="top"><br /><div style="padding-left:8px;"><h2>'.$row['headline'].'</h2><a href="#">Læs mere</a></div></td>');
$i++;
$p++;
}
else
{
$i = 0;
$p = 0;
}
}
?>
</table>