title: PDO Query Relating tables and display outcome
body: <p>I'm new to PHP and currently in process of learning PDO and getting away from MySQLi, I'm a student at college in CMS and I am following this course where the teacher wants me to relate two tables and display them, his MySQLi code looks like this</p>
  
  <pre><code>$query = "SELECT * FROM categories WHERE cat_id = {$post_category_id}";
  $select_categories_id = mysqli_query($connection,$query);
  
  while($row = mysqli_fetch_assoc($select_categories_id)) {
      $cat_id = $row['cat_id'];
      $cat_title = $row['cat_title'];
      echo "&lt;td&gt;{$cat_title}&lt;/td&gt;";
  }
  </code></pre>
  
  <p>And my PDO code looks like this, which is not working as it should...</p>
  
  <p>I've done several PDO queries before in my course but somehow this doesn't work.</p>
  
  <pre><code>$query = "SELECT * FROM categories WHERE cat_id = :post_category_id";
  $result = $connection-&gt;prepare($query);
  $result-&gt;execute(array(":post_category_id"=&gt;$post_category_id));
  while($row=$result-&gt;fetch(PDO::FETCH_ASSOC)){
      extract($row);
      $cat_id = $row['cat_id'];
      $cat_title = $row['cat_title'];
      echo "&lt;td&gt;$cat_title&lt;/td&gt;";
  }
  </code></pre>
  
  <p>I would appreciate any and all suggestions</p>