1

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?

2

1 Answer 1

4

This line below only fetches 1 row:

$apps = $stmt->fetch(PDO::FETCH_ASSOC);

Use fetchAll instead:

$apps = $stmt->fetchAll(PDO::FETCH_ASSOC);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.