我正在通过将结果最大记录限制为 4 的查询来查询 MySQL 数据库中的某些记录,但我想将所有“keep_actual”列设置为 1 但排除所有以前创建的记录的记录添加到此结果中。做这个的最好方式是什么?
// Sample query which return those 4 i need
// Result should be those 4 + all from current $cat which has keep_actual=1 but not are in those first 4
$news = $ed->getByLanguage($lang_id, null, false, 4,false,true);
public function getByLanguage($lang, $cat=null, $main=true, $limit=null, $hasImage=false, $isTopped=false) {
if ($cat == null) {
$where = "language_id=$lang";
} else {
$where = "language_id=$lang and category_id=$cat";
}
if ($main == false && $isTopped==false) {
$where.=" and main=0";
}
if ($hasImage == true) {
$where.=" and main_picture is not null";
}
if($cat==12){
$limit=10;
}
//Nastavuje, zda se ma zobrazovat top nebo ne(na uvodni strane a aktualne)
if($isTopped==true)
$where.=" and top = 1";
//=========================================================
//$where.=" and entry.date >= '".date("Y-m-d h:i:s", mktime(0, 0, 0, 1, 1, date("Y")))."' and entry.date <= '".date("Y-m-d h:i:s")."'";
if ($limit == 1) {
//nahledy
return parent::selectOne($this->sc->select("entry", "main_picture,url,name,abstract,date,top", $where, null, "date", $limit));
} else {
//main clanek
return parent::selectAll($this->sc->select("entry", "*", $where, null, "date", $limit));
}
}
public function selectAll($sql) {
$res = mysql_query($sql);
if ($res) {
$a = array();
$i = 0;
while ($r = mysql_fetch_assoc($res)) {
// print_r($r);
foreach ($r as $k => $v) {
$a[$i][$k] = $v;
}
$i++;
}
return $a;
} else {
return false;
}
}