i am trying to get all the result from my databse table but this query is not working.

<?php 
 try
   {
   $pdo = new PDO('mysql:host=localhost;dbname=articles', 'Avik', '');
   }
   catch (PDOException $e)
   {
   $output = 'Unable to connect to the database server.';
   echo $output;
   exit();
   }
   try
   {
   $sql = 'SELECT * FROM `post_series`';
   $result = $pdo->query($sql);
   }
   catch(PDOException $e)
   {
   echo "something wrong";
   exit();
   }
   foreach ($result as $row)
   {
   $series_options[] = array(
   'post_series_id_option' => $row['post_series_id'],
   'post_series_name_option' => $row['post_series_name']
    );
   }

 echo $series_options['post_series_name_option'];

 ?>

it gives me a error :

Notice: Undefined index: post_series_name_option in E:\wamp\www\test.php on line 30

After executing query you need to fetch the results first. See my code snippet. $result does NOT contain the returned rows.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.