title: Select all posts in current category and sub-categories
body: <p>I want recursively select all subcategories of current category</p>
  
  <pre><code>Table: categories
  Columns: catid, parent_id, cattitle
  </code></pre>
  
  <p>And select all postid in map table via returned catid(s) </p>
  
  <pre><code>Table: posts_categories
  Columns: postid, catid 
  </code></pre>
  
  <p>And finaly echo all postsubject  from posts table And thumnail image from attachments table</p>
  
  <pre><code>Table: posts in multi categories
  Columns: postid, postsubject
  
  Table: attachments
  Columns: attid, postsID,atturl
  </code></pre>
  
  <p>My purpose is echo all posts for current category and sub-categories with one thumnail attachment, in php by pdo</p>
  
  <blockquote>
    <p>Some code to start get subcategories...</p>
  </blockquote>
  
  <pre><code>    function getSubCat($rootid)
  {
  global $conn;
  global $cat_id;
  $arr = array();
  $stmt = $conn-&gt;prepare("SELECT catid,cattitle,parent_id,catapprove 
  FROM categories 
  WHERE parent_id = :parent_id AND catapprove = :catapprove ORDER BY catid ASC");
  $stmt-&gt;bindValue(":parent_id", $rootid, PDO::PARAM_INT);
  $stmt-&gt;bindValue(":catapprove", 1, PDO::PARAM_INT);
  $stmt-&gt;execute();
  WHILE ( $row = $stmt-&gt;fetch( PDO::FETCH_ASSOC ) ) {
  $arr[] = getSubCat($row["catid"]);
  }
  return $arr;
  }
  </code></pre>
  
  <p>But I not achieved results</p>