xeirus Posted May 29, 2011 Share Posted May 29, 2011 Hi! I have a table called "Categories" Here is the structure: id | Categories | ParentCategories 1 | Rings | Parent Category 2 | Pendants | Parent Category 3 | Ladies Rings | Rings 4 | Ladies Pendants | Rings 5 | Gents Rings | Gents 6 | Necklaces | Parent Category But Necklaces is one of those who is not going to have any subcategories or you can say, it is going to be a category by itself. So how can I construct a php statement to get data out of MySQL to determine that Necklaces is a Category which does not have subcategories. Please help ! Thank you ! - Xeirus. Quote Link to comment https://forums.phpfreaks.com/topic/237789-compare-two-columns/ Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 You can use a query to select all categories whose parent categories is equal to Necklaces. If there are 0 rows returned (which their should be) Then that means that Necklaces is a category without any sub categories. Quote Link to comment https://forums.phpfreaks.com/topic/237789-compare-two-columns/#findComment-1221933 Share on other sites More sharing options...
xeirus Posted May 29, 2011 Author Share Posted May 29, 2011 You can use a query to select all categories whose parent categories is equal to Necklaces. If there are 0 rows returned (which their should be) Then that means that Necklaces is a category without any sub categories. Thanks milesta707 but ... in this case I will have to embed Necklaces in my code which won't help the client as the client will be adding more and more such categories from time to time. So with your solution, I would have to hard-code the category name each time, which would bring me back to square-1. Hope I'm making sense... - Xeirus. Quote Link to comment https://forums.phpfreaks.com/topic/237789-compare-two-columns/#findComment-1221935 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 well clearly what I wrote was just an example. You could (and should) use a variable in your query, not the string necklace. I just wrote necklace because that was what you mentioned in your OP. Quote Link to comment https://forums.phpfreaks.com/topic/237789-compare-two-columns/#findComment-1221937 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.