Jump to content

Recommended Posts

hello guys this seems simple but not in my case as per now.

 

i have a table of categories with

 

cat_id -------------------cat_parent_id----------- cat_name

7 ------------------------- 0 ---------------------- cat1

9 --------------------------- 0----------------------- cat2

11 -----------------------------7------------------------ cat3

 

 

now am using these categories as a menu on the front page. i have made a query that calls only cats that have a 0 for parent thats fine.

in this case

 

cat1 and cat2 are the main menu.

 

i want to have an icon on a category that has a child which is cat3 that will show a user that if they point a cursor there, they will see hiden childrens.

 

the proble is am on a home page that has no query in the url that i can use as a reference in my sql query.

 

what kind of query can i do to put an icon on cats that have a child? before even a use clicks on it.

Edited by 50r
Link to comment
https://forums.phpfreaks.com/topic/271857-mysql-select-question/
Share on other sites

You need to join the table to itself with a left join

 

SELECT a.cat_id, a.cat_parent_id, a.cat_name, b.cat_id
FROM category a
LEFT JOIN category b ON a.cat_id = b.cat_parent_id
WHERE a.cat_parent_id = 0

 

b.cat_id will be NULL where there is no child

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.