0

I want recursively select all subcategories of current category

Table: categories
Columns: catid, parent_id, cattitle

And select all postid in map table via returned catid(s)

Table: posts_categories
Columns: postid, catid 

And finaly echo all postsubject from posts table And thumnail image from attachments table

Table: posts in multi categories
Columns: postid, postsubject

Table: attachments
Columns: attid, postsID,atturl

My purpose is echo all posts for current category and sub-categories with one thumnail attachment, in php by pdo

Some code to start get subcategories...

    function getSubCat($rootid)
{
global $conn;
global $cat_id;
$arr = array();
$stmt = $conn->prepare("SELECT catid,cattitle,parent_id,catapprove 
FROM categories 
WHERE parent_id = :parent_id AND catapprove = :catapprove ORDER BY catid ASC");
$stmt->bindValue(":parent_id", $rootid, PDO::PARAM_INT);
$stmt->bindValue(":catapprove", 1, PDO::PARAM_INT);
$stmt->execute();
WHILE ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
$arr[] = getSubCat($row["catid"]);
}
return $arr;
}

But I not achieved results

netlover
  • 11
  • 3
  • this query get result from 4 tables, and aim More than your link – netlover Jul 01 '16 at 18:01
  • My question is not recursively categories, The rest of the process is important, please read again – netlover Jul 01 '16 at 18:06
  • But you said _" want recursively select all subcategories of current category_"; once that part is answered, the rest is fairly trivial. – Uueerdo Jul 01 '16 at 18:17

0 Answers0