User built navigation help
I am currently trying to build a navigation that is semi built by the user, basically the user has a primary navigation in which if they click on a category name a block is created on the page for that category. If they click the same link again the block is removed from the page, the website is set up to remember which blocks the user had chosen on there last vist, my issue is getting the menu to display properly.
The way the menu works is that the primary navigation links are built and when the user clicks a link that link gets given a class of "saved" when they click it again the class "saved" is removed.
When the user returns to the site, the primary nav links should have the class saved if there associated block is displaying.
What I need to do is to find a way to get all the links for the primary nav out of the database and check if they links have been chosen by the user in their last vist.
The database structure is like this,
THIS IS TABLE THAT HOLDS MY PRIMARY LINKS
CREATE TABLE categoryTable (
categoryId int(11) NOT NULL auto_increment,
categoryTitle varchar(25) NOT NULL,
categoryAbstract varchar(60) NOT NULL,
categorySlug varchar(25) NOT NULL,
categoryIsSpecial int(1) NOT NULL,
categoryOnline i开发者_运维知识库nt(1) NOT NULL,
categoryDateCreated int(10) NOT NULL,
dashboardUserId int(11) NOT NULL,
PRIMARY KEY (categoryId)
)
AND THIS IS TABLE THAT HOLDS THE INFORMATION ON WHAT BLOCKS THE USER HAS OPEN
CREATE TABLE userMenuTable (
menuEntryId int(11) NOT NULL auto_increment,
categoryId int(11) NOT NULL,
cookieId varchar(32) NOT NULL,
PRIMARY KEY (menuEntryId),
KEY categoryId (categoryId,cookieId),
KEY cookieId (cookieId)
)
I tried this query to get all the categories that are not in the userMenuTable but it does not work,
SELECT *
FROM `categoryTable`
WHERE `categoryId`
NOT IN (
SELECT `userMenuTable`.`categoryId`
FROM (`userMenuTable`)
LEFT JOIN `categoryTable` ON
`categoryTable`.`categoryId` = `userMenuTable`.`categoryId`
WHERE `userMenuTable`.`cookieId` = '{$cookieId}')
I am obviously doing something wrong can anybody shed any light on my problem?
Why are you using NOT IN
in your query above? It seems IN
would be more appropriate. Anyway, here's a simpler/more efficient query that should work:
SELECT cat.*
FROM userMenuTable user
LEFT JOIN categoryTable cat ON cat.categoryId = user.categoryId
WHERE user.cookieId = '{$cookieId}'
精彩评论