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
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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.