mardi 5 avril 2016

Want to show multiple categories using category id

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: enter image description here

Here is the categories table's screenshot:
enter image description here

Aucun commentaire:

Enregistrer un commentaire