This is a query run in 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
This returns five rows ( Showing rows 0 - 4 ( 5 total, Query took 0.0008 sec)
) and I can see that the rows are correct.
Here is my PHP code executing the query:
$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();
}
This outputs:
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
)
Why is this not outputting all the rows returned by the SQL query?
This line below only fetches 1 row:
$apps = $stmt->fetch(PDO::FETCH_ASSOC);
Use fetchAll
instead:
$apps = $stmt->fetchAll(PDO::FETCH_ASSOC);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.