0
while循環中的前兩個if/elseif語句正在檢查新聞項目是否存在圖像,如果沒有,它會跳過它。櫃檯確保只有頂部的前三個項目才能完成。目前這工作正常,沒有任何錯誤。PHP查找包含圖像的項目幷包含在頂部
我想要前兩個如果/ elseif語句只使用圖像的帖子($ row-> imagelibid) - 所以可能有一個7天前的圖像的新聞故事,所以它使用頂部 - 它不得不用圖像尋找和使用新聞報道。這意味着這些「選定」故事的日期順序會錯誤 - 但沒關係。
希望是有道理的...和任何幫助我欣賞。
$site_url = "http://www_#_com";
$full_site_url = $site_url . "/" . $news_prefix . "news/" . $row->id;
$news_prefix = "#";
$adFrequency = 5;
$ad = 0;
$i = 0;
$result = mysql_query("SELECT news.*, regions.name AS territory FROM news JOIN country ON news.country = country.iso JOIN regions ON regions.id = country.region WHERE news.mobile_app != 0 AND news.hidden = 0 AND news.beef = 1 ORDER BY news.datein DESC LIMIT 20", $db);
while (($row = mysql_fetch_object($result)) !== false) {
$imageid = intval($row->imagelibid);
$image_result = mysql_query("SELECT * FROM imagelib WHERE id = {$imageid}", $db);
$image_row = mysql_fetch_object($image_result);
$image_url = "http://www.#.com/slir/w280/imagelib/" . $image_row->id . "_" . $image_row->filename;
if ($i <= 0 && !empty($row->imagelibid)) {
echo '<div class="one-news-featured-article clearfix">';
echo '<div class="grid_12">';
echo '<div class="large-featured-image-container"><img src="'.$image_url.'">';
echo '<div><h2><a href="item-news.php?id='.$row->id.'">'.$row->title.'</a></h2></div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
elseif ($i <= 2 && !empty($row->imagelibid)) {
echo '<div class="one-news-featured-article clearfix">';
echo '<div class="grid_6">';
echo '<div class="small-featured-image-container"><img src="'.$image_url.'">';
echo '<div><h2><a href="item-news.php?id='.$row->id.'">'.$row->title.'</a></h2></div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
else {
// Places ad based of predefined variable frequency
if ($ad == $adFrequency){
echo'<div class="one-advertisement-article clearfix">';
echo'<div class="grid_9 suffix_2"><img src="http://placehold.it/263x75/000000/ffffff"></div>';
echo'<div class="grid_1"><a class="navigate-right-icon ss-icon" href="#">navigateright</a></div>';
echo'</div>';
$ad = 0;
}
echo '<div class="one-news-article clearfix">';
if($row->imagelibid)
{
echo '<div class="grid_4"><a href="#"><img src="'.$image_url.'"></a></div>';
}
else {
echo '<div class="grid_4"><div class="news-placeholder"><span class="ss-icon">ellipsischat</span></div></div>';
}
echo '<div class="grid_7">';
echo '<h2><a href="item-news.php?id='.$row->id.'">'.$row->title.'</a></h2>';
$published_date = date('D, d M Y', strtotime($row->datein));
echo '<p class="published-date">'.$published_date.'</p>';
echo '<p class="news-snippet">'.$row->snippet.'</p>';
echo '</div>';
echo '<div class="grid_1">';
echo '<div class="news-item-vertical-sep"> </div>';
echo '<p></p>';
echo '</div>';
echo '</div>';
$ad++;
}
$i += 1;
}
P.S我知道mysql_是一個不推薦使用的函數,但是如果現在這可能被忽略,那會很好。
你可以發佈你的數據庫表結構嗎? – dualed