Jump to content

Where do i put this little bit


npsari

Recommended Posts

I have this little php code

in which, i join two tables

 

$qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id
FROM category c
LEFT JOIN topic t
ON t.topic_category_id = c.category_id
ORDER BY c.category_id ASC";

 

I want to add this bit

 

COUNT(t.topic_category_id) as CNT

 

Where do i put it in the above code

 

Wherever i add it, the query does not work completely

 

i tried for example

 

$qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id
COUNT(t.topic_category_id) as CNT
FROM category c
LEFT JOIN topic t
ON t.topic_category_id = c.category_id
ORDER BY c.category_id ASC";

 

It doesnt work

Link to comment
https://forums.phpfreaks.com/topic/91732-where-do-i-put-this-little-bit/
Share on other sites

That's because you need a comma right before it to separate it from the previous select.

 

$qX = "SELECT c.category_name, c.category_id, c.category_info, t.topic_category_id, 
COUNT(t.topic_category_id) as CNT
FROM category c
LEFT JOIN topic t
ON t.topic_category_id = c.category_id
ORDER BY c.category_id ASC";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.