i'm working on a blog and i want to show multiple categories by using category ids, below is the code i'm working on :
// here $post['cat_id'] = "4,2,3"
// (I fetched above mentioned values from posts and categories table by using INNER JOIN)
$str_cat = $post['cat_id'];
$str_cat = explode(',', $str_cat);
$CountVal = count($str_cat);
if($CountVal <= 1){
echo $post['cat_name']; //This will show only one category name i.e. "Test Category"
}else{
// Here It should be show like "Test Category, Category2, Category3"
}
I'm beginner in php and i'm little confused with this code. Anyone can help me???
Here is the posts table's screenshot:
Here is the categories table's screenshot:
Aucun commentaire:
Enregistrer un commentaire