while 循环中的前两个 if/elseif 语句正在检查新闻项目的图像是否存在,如果不存在,则跳过它。柜台确保仅对顶部的前三个项目执行此操作。目前这工作正常,没有任何错误。
我希望前两个 if/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;
}
PS 我知道 mysql_ 是一个已弃用的函数,但如果现在可以忽略它,那就太好了。