Udders
Udders

Reputation: 6976

SQL help query not returning all data,

I am building a website that remembers the users choices from a navigation menu and then shows content the next time they visit the webiste there last view content is available, to this I am running this query

SELECT * FROM (`categoryTable`) 
    LEFT JOIN `userMenuTable` 
        ON `userMenuTable`.`categoryId` = `categoryTable`.`categoryId`

This returns in PHPmyAdmin all the relative results however when running in it through my website it returns the relative but it does not return the categoryId if the categoryyId does not exists in the UserMenutable.

What I need is a way to what the user has saved and pull those results out and then find out what he hasnt saved and then do something else

Is this possible?

Upvotes: 2

Views: 152

Answers (1)

KM.
KM.

Reputation: 103579

just a guess, but if you are accessing the yourResultSetHere['categoryId'], you are getting the null from the it from userMenuTable and not the value from categoryTable. You should try changing SELECT * into:

SELECT
    col1, col2
        ,categoryTable.categoryId AS c_categoryId 
        ,userMenuTable.categoryId AS u_categoryId
        , col3 
    ...

and see if you get the value in c_categoryId

Upvotes: 1

Related Questions