此代码显示表“条目”中存储在数据库中的所有名称的列表。
我有200个名字的清单。前20名标记为绿色。最后20红。其他人都是蓝色的。
$position=0;
$upit = mysql_query("SELECT * FROM entries ORDER BY votes DESC");
//This is now an array of the data
while ($model = mysql_fetch_array($upit)) {
$position++;
$data = unserialize($model['data']);
$max = mysql_num_rows($upit);
$max = $max - 20;
if ($position < 21){
echo " <font color=#008000> ".$position." ) ".$data[6]['value']." ( ".$model[votes]." ) </font>";
} elseif ($position <= $max) {
echo " <font color=#000080> ".$position." ) ".$data[6]['value']." ( ".$model[votes]." ) </font>";
} else {
echo " <font color=#FF0000> ".$position." ) ".$data[6]['value']." ( ".$model[votes]." ) </font>";
}
}
此CODE以下列方式显示列表
1. Novak Djokovic (1342)
2. Rafael Nadal (1234)
3. Roger Federer (1002)
4. Name 4 (990)
5. Name 5 (899)
6. ...
现在我想从列表中列出两个名称,但它们不会从数据库中删除。 每个名称在表“条目”中都有自己唯一的ID,称为“entries_id”。
例如,我想要不在列表中 诺瓦克·德约科维奇的“entries_id”是“150” 和Roger Federes的软管“entries_id”是“92”
答案 0 :(得分:1)
只需相应地更新您的查询
SELECT * FROM entries WHERE entries_id<>150 AND entries_id<>92 ORDER BY votes DESC
即使它们存在于您想要的数据库中,您也不会在结果中获得这两条记录。
答案 1 :(得分:0)
试试这个:
...
$count = 0;
while ($model = mysql_fetch_array($upit)) {
$position++;
$data = unserialize($model['data']);
$max = mysql_num_rows($upit);
$max = $max - 20;
if (!($data[6]['value'] == 150 || $data[6]['value'] == 92)){
$count++;
if ($count< 21){
echo " <font color=#008000> ".$position." ) ".$data[6]['value']." (".$model[votes]." ) </font>";
} elseif ($count<= $max) {
echo " <font color=#000080> ".$position." ) ".$data[6]['value']." ( ".$model[votes]." ) </font>";
} else {
echo " <font color=#FF0000> ".$position." ) ".$data[6]['value']." ( ".$model[votes]." ) </font>";
}
}
}