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