這個新板不合邏輯的邏輯有些幫助,但愛它到目前爲止:)需要對PHP + MySQL和HTML表格
我目前正在幫助一個朋友的礦井重做她的個人網站,我跑我的頭靠在桌子上的邏輯牆。
該表suppossed顯示在表的最新消息,包括4 columens /電池/ TDS PR行(僅此而已) - looing是這樣的: 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>
我假設'$ p'是'$ i'的弟弟,只是複製'$ i'的所有內容,因爲他認爲他很酷。 – Rhys 2012-07-31 12:06:23
不應再使用MySQL函數。而是使用MySQLi或PDO來訪問您的數據庫。 – Lusitanian 2012-07-31 12:08:18
你試圖把image1 n date1放在row1,col1(html表格)&headline1放在row2,col1第一次執行循環? – Makesh 2012-07-31 12:10:07