Jump to content

Filtering a recordset with the users id


coppens

Recommended Posts

I am using Dreamweaver and would like the results of a page to display records that have the same variable as the user that has logged in.  For instance, if User A works at 'Daycare A' and 'Daycare A' is coded as workplace '5'.  How do I word the statement that all persons who work at workplace '5' appear on the page.  The pages are already filtered to follow the user through by username.  However I need the new filter to look at the users record, choose the column 'ChildcareID' and display all others from that Childcare.  I currently have this statement.

 

SELECT *
FROM users
WHERE ChildcareID = colname
ORDER BY LastName ASC
 
Name: colname
Type: Integer
Default value: -1
Run-time value: $_SESSION['MM_Username']
 
Thank you
Link to comment
Share on other sites

I am using the coding wizards.  I want to pull the ChildcareId of the session user.  The session is followed by the users 'username'.  The table has UserId, UserName, ChildcareID, and UserLevel.  I need the filter to look at the ChildcareID of the current user and filter all users with the same ID as well as only choosing those users with a userlevel of 1.

 

Please help.

 

Thank you

Link to comment
Share on other sites

Assuming the data looks something like this

+--------+----------+-------------+
| userid | username | childcareid |
+--------+----------+-------------+
|      1 | Albert   |           1 |
|      2 | Betty    |           2 |
|      3 | Charlie  |           3 |
|      4 | Diane    |           1 |
|      5 | Edward   |           2 |
|      6 | Fiona    |           3 |
|      7 | Graham   |           1 |
|      8 | Helen    |           2 |
|      9 | Ian      |           3 |
|     10 | Jane     |           1 |
+--------+----------+-------------+

then the query you want is (if logged in user has id=1)

SELECT 
	u2.username
  , u2.childcareid
FROM users u1
INNER JOIN users u2 USING (childcareid)
WHERE u1.userid = 1                         -- logged user
+----------+-------------+
| username | childcareid |
+----------+-------------+
| Albert   |           1 |
| Diane    |           1 |
| Graham   |           1 |
| Jane     |           1 |
+----------+-------------+
Link to comment
Share on other sites

Can't recommend enough not using the wizards. I've used DreamWeaver since before Macromedia released the studio bundle, and only used the wizards once in all that time (I keep using DW because I got used to the code coloring and, well, I already have it... Though admittedly I'm looking at different IDEs now). The pre-buit code is bloated, confusing, and badly written. I honestly think you'll be much better off hand-coding any changes you need made.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.