0

I have the following that returns data from my table...

    $query = dbConnect()->prepare("SELECT * FROM users a INNER JOIN actions b ON a.id = b.user_id WHERE a.id=:user_id");
    $query->bindParam(':user_id', $_SESSION['user_id']);
    $query->execute();


    if($row = $query->fetchAll()){
        $row['id'] = $_SESSION['user_id'];
    }

I want to print out every value in my 'check_id' column for the currently logged in user...

I've tried...

 if($row = $query->fetchAll()){
        $row['id'] = $_SESSION['user_id'];
        $checkValue = $row['check_id'];
    }

Only i receive...

Notice: Undefined index: check_id in /home/index.php on line 24

Printing the array shows my check_id value...

enter image description here

3
  • 1
    Is there a column named check_id in users table? Commented Oct 3, 2014 at 15:59
  • Theres a column yes but its in my actions table @ekad Commented Oct 3, 2014 at 16:00
  • fetchAll() returns a multidimensional array, so try -> $checkValue = $row[0]['check_id'];. Or you could change to if($row = $query->fetch()){ Commented Oct 3, 2014 at 16:20

2 Answers 2

2

You need to;

  • Fetch all the results
  • Iterate through your result set

$arrResults = $query->fetchAll();
foreach($arrResults as $result) {
   echo $result['user_id'] . PHP_EOL;
}
Sign up to request clarification or add additional context in comments.

Comments

0

To debug use print_r

if($row = $query->fetchAll()){
    print_r($row);
}

1 Comment

I've updated my question with the reply @JohanSnowgoose

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.