我正在尝试使用if else语句在我的首选列表中突出显示一个网站。当我检查服务器的元素,它应该是赞助商网站时,它不会显示为“赞助商网站”css,它仍然以闪烁(赞助商= 0)的形式出现。我不确定我是否真的在检查该网站是否是赞助商?
<?php
require_once('mysql_connect.php');
$query = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites ORDER BY votes DESC LIMIT 50";
$result = mysql_query($query) OR die(mysql_error());
// Rank counter
$rank = 1;
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//it would wrap your text upto 20 characters
$wrappedText = wordwrap(substr($row['description'], 0, 200), 55, "<br />\n", true);
if(sponsor == 0){
echo '<tbody>
<tr class="server glossed site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" rel="no_follow" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$wrappedText.'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>';
} else {
echo '<tbody>
<tr class="server sponsor site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" rel="no_follow" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$wrappedText.'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>';
}
$rank++;
}
?>
答案 0 :(得分:0)
你可能也看到了PHP错误。无论哪种方式,你的while语句都会循环查询结果,因为它是一个数组因此,你必须改变
if(sponsor == 0){
到
if ($row['sponsor'] == 0) {
这应该会给你预期的结果。