-1
我試着用倍數參數,以獲得使用SELECT COUNT(*)的行數,它編碼的JSON格式的數字,但我得到這個:如何計算行用SELECT COUNT(*)
{"notification":[{"count(*)":0}],"message":[{"count(*)":0}]}
相反的除外:
{"notification":0,"message":0}
有頁面,這裏的代碼:
session_start();
require_once __DIR__ . '/mysql/Db.class.php';
$bdd = new Db();
$t = array();
$query = $bdd->query("SELECT count(*) FROM notification WHERE id_proprio = :id_proprio AND readed = :readed", array("id_proprio"=> $_SESSION['userid'],"readed"=>"0"));
$query_2 = $bdd->query("SELECT count(*) FROM discussion WHERE id_1 = :uid AND readed = :readed AND notifPour = :uid2 OR id_2 = :uid3 AND readed = :readed2 AND notifPour = :uid4", array(
"uid"=> $_SESSION['userid'],
"readed"=>"0",
"uid2"=> $_SESSION['userid'],
"uid3"=> $_SESSION['userid'],
"readed2"=>"0",
"uid4"=> $_SESSION['userid']
));
$t["notification"] = $query;
$t["message"] = $query_2;
echo json_encode($t);
包括類d的一部分B:
public function query($query,$params = null,$fetchmode = PDO::FETCH_ASSOC)
{
$query = trim($query);
$this->Init($query,$params); // INIT IS THE CONNECTION TO DB
if (stripos($query, 'select') === 0) {
return $this->sQuery->fetchAll($fetchmode);
}
elseif (stripos($query, 'insert') === 0 || stripos($query, 'update') === 0 || stripos($query, 'delete') === 0) {
return $this->sQuery->rowCount();
} else {
return NULL;
}
}
如何,我可以得到例外的結果格式是這樣的:
{"notification":0,"message":0}
謝謝。
謝謝求助 !它工作完美! –