Link to home
Start Free TrialLog in
Avatar of Ike McMahon
Ike McMahonFlag for United States of America

asked on

PHP query ends up with an array inside of an array - please help!

Hello all!  Thanks for taking a look at this...

I've set up a PDO connection string in PHP, which works fine.  I'm using the code below to run a simple query that should return a single line from the database.  The query appears to be working fine, but when I do a var_dump on the results, I get an array inside of an array.  It's like it's adding an extra "layer" of array.  Instead of just an array with the elements, it creates and array with one element that contains another array with the expected elements.  Please see the results below:

I'm hoping that you can help save the little hair I have left - it's coming out in clumps!

Here's the code, and the var-dump results are below it...

<?php  // Get existing values of case id if present in DB
$my_id = trim(strip_tags($_SESSION['my_id']));
try {
      $case_res = $pdo->query("SELECT m_city, m_state, m_country FROM user_info where my_id = '" .  $my_id . "'");

}catch (Exception $e){
      echo "Not Successfull:  Unable to read Case ID";
      }
      
echo "<pre>";      
//var_dump($case_res->fetchAll());      
var_dump($case_res->fetchAll(PDO::FETCH_ASSOC));
?>

Here are the results:

array(1) {
  [0]=>
  array(3) {
    ["m_city"]=>
    string(9) "hollywood"
    ["m_state"]=>
    string(2) "CA"
    ["m_country"]=>
    string(4) "Togo"
  }
}
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ike McMahon

ASKER

Dave you are my hero.  Good thing this wasn't a snake!  I've been staring at it for two hours.  Thanks again!
A real lifesaver - thanks!

Ike
You're welcome, glad to help and I avoid snakes.