php - Get category on topic id -


so want category name showed on id of topic. have this

        $cato = $db->prepare('select                         topics.topic_cat,                         topics.topic_id,                         categories.cat_id,                         categories.cat_name                                             topics                     left join                         categories                     on                         topics.topic_cat = categories.cat_id                                             topics.topic_id =:topid');  $cato->bindparam(':topid',  $row2["topic_id"], pdo::param_int);  $cato->execute(); $result2 = $cato->fetch(); 

categories.cat_id id of category.

categories.cat_name name want get.

topics.topic_cat category id topic posted ( same id categories.cat_id)

topics.topic_id id of topic (topic.php?id=28)

my result needs

topic 28 in category hello (hello = categories.cat_name).

so, short: topic id 28 searches in topics row topic_id 28 , grabs topic_cat in same row topic_id 28. looks in categories , grabs categories_name topic_cat. posts categories_name

i hope clear enough.

can try:

select topics.topic_cat,        topics.topic_id,        categories.cat_id,        categories.cat_name topics, categories topics.topic_cat = categories.cat_id       , topics.topic_id =:topid 

this should work unless have topic without category.


Comments