这是我喜欢在 MYSQL_QUERY 中说的话
$query = "SELECT (SELECT COUNT(type) FROM msg WHERE view = 0 AND nd = 'test' AND type = 0) as inbox,
(SELECT COUNT(type) FROM msg WHERE view = 0 AND nd = 'test' AND type = 1) as sent,
(SELECT COUNT(type) FROM msg WHERE view = 0 AND nd = 'test' AND type = 2) as draft,
(SELECT COUNT(type) FROM msg WHERE view = 0 AND nd = 'test' AND type = 3) as spam,
(SELECT COUNT(type) FROM msg WHERE view = 0 AND nd = 'test' AND type = 4) as trash";
我喜欢使用 PDO,我试过这个,但我得到了一个错误:
$query=$db->prepare("SELECT
(SELECT COUNT(*) as inbox FROM msg WHERE view = :view AND nd = :nd AND type = :type),
(SELECT COUNT(*) as sent FROM msg WHERE view = :view AND nd = :nd AND type = :type),
(SELECT COUNT(*) as draft FROM msg WHERE view = :view AND nd = :nd AND type = :type),
(SELECT COUNT(*) as trash FROM msg WHERE view = :view AND nd = :nd AND type = :type)
");
$query->execute(array(
':view' => 0,
':nd' => 'test',
':type' => 1
));
$pageRow=$query->fetch(PDO::FETCH_NUM);
$inbox = $pageRow[0];
$sent = $pageRow[1];
$draft = $pageRow[2];
$trash = $pageRow[3];