close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Filter data in select to omit records related to logged in user.

Thread began 3/01/2011 12:57 pm by troyd | Last modified 3/21/2011 10:45 am by troyd | 1916 views | 16 replies

troyd

Filter data in select to omit records related to logged in user.

I wasn't sure where to post this. I can add more details but figured I would start with the basics in hopes it was just something I wasn't grasping but might be an easy fix.

I have a page that people will log in to and then see a list of event dates. They will also see a form with 2 selects. A drop down select with the event date and a second with a number of tables to choose. This form inserts a record into a relational table. All of this is working.

Everything working but the date drop down. See, it's still showing a date that is already in the user's reserved list.



Here are two of my tables. (there's a third for users info.)

Parent event table



Child user to event table



Here's what I need. Since the dropdown is dynamically populated by a recordset, it needs to show only dates that the user has not already registered for. Basically the opposite of the other list that displays the events they DID register for. I need this list (drop down in form) to show the events they did not register for.

My attempts so far have given me partial results.

Here is my SQL for the list that shows their registrations.
SELECT users.UserID, date_format(show_date, '%M %e, %Y') as show_date, UserFirstName, UserLastName, reserved
FROM tblbooths LEFT JOIN tblreserved ON tblbooths.booth_id = tblreserved.booth_id
LEFT JOIN users ON users.UserID = tblreserved.UserID
WHERE tblreserved.UserID = ParamUserID
GROUP BY show_date

(with)

ParamUserID
integer
-1
$_SESSION['UserID']


How would I create the opposite that would show all event dates that the user has not already registered for? Seems simple I know. But using WHERE UserID != ParamUserID won't do it because there are records that do not have the user's id in it, but still have the date they already registered for. So I tried HAVING so it would do it after the grouping of dates. That partially works, but still leaves a couple dates in there for some reason.

SQL for the select that I have tried, but doesn't work.
SELECT capacity, date_format(show_date, '%M %e, %Y') as show_date, tblbooths.booth_id, COALESCE(sum(reserved), 0) AS total, UserID, capacity - COALESCE(sum(reserved), 0) AS available
FROM tblbooths LEFT JOIN tblreserved ON tblbooths.booth_id = tblreserved.booth_id
WHERE show_date >= CURDATE()
GROUP BY show_date
HAVING UserID != ParamUserID


Ideally I would like just one recordset that worked for both areas. But that's not a big deal. On that note. Is there a way to bind the first recordset to both areas in php and maybe an if statement? I would alter it a little. Just a thought.

Thanks,
TroyD

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