Avatar of ike1492
ike1492
 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"
  }
}
PHPMySQL ServerSQL

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ike1492

ASKER
Dave you are my hero.  Good thing this wasn't a snake!  I've been staring at it for two hours.  Thanks again!
ike1492

ASKER
A real lifesaver - thanks!

Ike
Dave Baldwin

You're welcome, glad to help and I avoid snakes.
Your help has saved me hundreds of hours of internet surfing.
fblack61