close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Help with SQL query

Thread began 12/07/2015 11:16 am by iain331081 | Last modified 12/11/2015 4:03 pm by Ray Borduin | 1405 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.

Sign in to reply to this post

Ray BorduinWebAssist

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 product_likes.UserIDPL = %s AND product_likes.LodgeIDPL IS NULL
GROUP BY LodgeID

Sign in to reply to this post
Did this help? Tips are appreciated...

iain331081

Thanks Ray - that returns no results though.

Sign in to reply to this post

Ray BorduinWebAssist

How about:

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 AND product_likes.UserIDPL = %s
WHERE Product_Type = 'Property' AND product_likes.LodgeIDPL IS NULL
GROUP BY LodgeID

Sign in to reply to this post
Did this help? Tips are appreciated...

iain331081

That's returning all the records:

Sign in to reply to this post

Ray BorduinWebAssist

Your parameter name was wrong on line 111... you had:
GetSQLValueString($ParamUserID2_WADAlodgelikes, "int")

and it should be:
GetSQLValueString($ParamUserID2_WADAlodges, "int")

The query was correct

Sign in to reply to this post
Did this help? Tips are appreciated...

iain331081

Thanks Ray - paying too much attention to the SQL bit and missed that.

Sign in to reply to this post

iain331081

Just a quick follow up to this one - I realised there were five pages where this is an issue. I have it correct on four, but can't seem to get it correct on the search results page. So the same idea - if someone connects to a product, that should no longer appear on the search results.

Details below...

Sign in to reply to this post

Ray BorduinWebAssist

Did you do this query by hand? You forgot the sprintf() function to replace the parameters, the code should be:

$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 AND product_likes.UserIDPL = %s
WHERE Product_Type = 'Property' AND product_likes.LodgeIDPL IS NULL
", GetSQLValueString($ParamUserID_WADAlodges, "int"));

Sign in to reply to this post
Did this help? Tips are appreciated...

iain331081

Thanks Ray - I did edit it by hand and missed that.

Sign in to reply to this post
loading

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...