1
這是在phpMyAdmin運行查詢:PHP SQL查詢不返回相同的行如在phpMyAdmin
SELECT app . *
FROM `tap_applications` app, `tap_jobs` job
WHERE job.id = app.job_id
AND job.closed =0
AND job.user_id =1
這將返回五行(Showing rows 0 - 4 (5 total, Query took 0.0008 sec)
),我可以看到行是正確的。
這裏是我的PHP代碼執行查詢:
$id=1;
$stmt = $dbh->prepare('SELECT app.*
FROM `tap_applications` app, `tap_jobs` job
WHERE job.id = app.job_id
AND job.closed = 0
AND job.user_id=?');
if($stmt->execute(array($id))){
$apps = $stmt->fetch(PDO::FETCH_ASSOC);
echo '<pre>'; print_r($apps); exit();
}
此輸出:
Array
(
[id] => 2
[job_id] => 6
[name1] => Ben
[name2] => //redacted
[tel] => //redacted
[email] => //redacted
[cv] => 6-Ben1424692150.pdf
[seen] => 0
[time] => 2015-02-23 11:57:33
[decision] => 1
)
這是爲什麼不輸出由SQL查詢返回的所有行?
http://php.net/manual/en/pdostatement.fetch.php:PDOStatement對象::提取 - 從結果集中提取下一行。 – Masiorama 2015-03-25 08:15:20
嘗試使用fetchAll函數。 – 2015-03-25 08:15:26