Help with SQL query
I have a page on a site using the following query:
SELECT DISTINCT LodgeID, Lodge, GSG_URL, banner_image_new, Country, banner_image_new_title, photo_one, photo_one_title, Summary_2013, lodges.CountryID, UserIDIT, LodgeIDPL, UserIDPL
FROM lodges
INNER JOIN countries ON lodges.CountryID = countries.CountryID
INNER JOIN product_users ON lodges.LodgeID = product_users.LodgeIDIT
LEFT JOIN product_likes ON lodges.LodgeID = product_likes.LodgeIDPL
WHERE Product_Type = 'Property'
GROUP BY LodgeID
which lists all lodges in the lodges table which have a corresponding country in the countries table, and also a user in a corresponding product_users table. (lodges and products are the same thing) And also lists them if whether there is or is not a record in the product_likes table.
The product_likes table is a simple table that records when the user currently logged in 'likes' a lodge.
However, what I am trying to have is that page list all the lodges that the user currently logged in has not yet liked. i.e. when they like a lodge, that lodge no longer appears on that list, but moves to a list of liked lodges. (which I have working).
I have been trying things like:
$ParamUserID_WADAlodges= "-1";
if (isset($_SESSION["SecurityAssist_UserID"])) {
$ParamUserID_WADAlodges = $_SESSION["SecurityAssist_UserID"];
}
mysql_select_db($database_connSafari, $connSafari);
$query_WADAlodges = sprintf("SELECT DISTINCT LodgeID, Lodge, GSG_URL, banner_image_new, Country, banner_image_new_title, photo_one, photo_one_title, Summary_2013, lodges.CountryID, UserIDIT, LodgeIDPL, UserIDPL
FROM lodges
INNER JOIN countries ON lodges.CountryID = countries.CountryID
INNER JOIN product_users ON lodges.LodgeID = product_users.LodgeIDIT
LEFT JOIN product_likes ON lodges.LodgeID = product_likes.LodgeIDPL
WHERE Product_Type = 'Property' AND UserIDPL <> %s
GROUP BY LodgeID
", GetSQLValueString($ParamUserID2_WADAlodgelikes, "int"));
i.e. basically just adding the condition UserIDPL <> UserID of the currently logged in User - so it should only list lodges that the user hasn't yet liked.
But I can't see to get it to work.
Not sure I have explained that too well, but hopefully you get what I mean.
Any pointers much appreciated.
Let me know if anything isn't clear. I have attached a copy of the page as it currently is.
Thanks again.