这是我的代码片段:
$other_query = $this -> db -> query("SELECT EXISTS(SELECT 1 FROM shops WHERE cid=$cid AND zbid!=0 AND zbid!=$zbid)",__LINE__,__FILE__);
$this -> db -> output_vars["other_shops"] = $this -> db -> get_result($other_query); // 1 = there are other shops, 0 = no other shops
if($group["shop_create"] == 0){
$my_shop = 3;
} else {
$my_shop_query = $this -> db -> query("SELECT EXISTS(SELECT 1 FROM shops WHERE cid=$cid AND zbid=$zbid LIMIT 1)",__LINE__,__FILE__);
$my_shop = $this -> db -> get_result($my_shop_query) == 1 ? 1 : 2;
}
我想将这两个查询合二为一。这两个查询之间的唯一区别是,一个查询 where 的行,zbid!=0 AND zbid!=$zbid而另一个查询 where 的行zbid=$zbid。这里的另一个问题是if声明。此外,在这种情况下$group["shop_create"] == 0(即在这个初始代码中,只会运行一个查询),我不希望组合查询做任何额外的工作。
对于那些好奇的人,$this -> db -> get_result($query_resource)基本上返回相当于mysql_result($query_resource,0). 我从 切换mysql到时添加了此功能mysqli。
我希望这是有道理的!