close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Help with SQL query

Thread began 12/07/2015 2:16 pm by iain331081 | Last modified 12/11/2015 7:03 pm by iain331081 | 773 views | 9 replies

iain331081

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.

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...