Solved

Trying to get Dreamweaver to filter data

Posted on 2004-08-08
5
169 Views
Last Modified: 2010-04-07
Hi, Let me first say I am a novice with ASP.

on this page: http://aasg.brinkster.net/admin/user_admin.asp , I am trying to show users in database based on the access level. I got dreamweaver to write the code below for me. However, it is not working for ALL USERS. The way the code is right now, when there is no URL parameter, the accesslevel is set to 1, so instead of all users, users with accesslevel 1 (called "subscribe") are shown. How do I get it to show ALL users, regardless of their accesslevel? I think I need to write a separate if/then statement saying if there is no accesslevel URL parameter, then use this other recordset. But I am not sure how I would do that.

Here's the dreamweaver code as it is right now:

<%
Dim rsUsers__MMColParam
rsUsers__MMColParam = "1"
If (Request.QueryString("accesslevel") <> "") Then
  rsUsers__MMColParam = Request.QueryString("accesslevel")
End If
%>
<%
Dim rsUsers
Dim rsUsers_numRows

Set rsUsers = Server.CreateObject("ADODB.Recordset")
rsUsers.ActiveConnection = MM_connSane1_STRING
rsUsers.Source = "SELECT * FROM qryUser_Admin WHERE userLevelID = " + Replace(rsUsers__MMColParam, "'", "''") + " ORDER BY lname ASC"
rsUsers.CursorType = 0
rsUsers.CursorLocation = 2
rsUsers.LockType = 1
rsUsers.Open()

rsUsers_numRows = 0
%>
0
Comment
Question by:polaatx
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:alexhogan
ID: 11749366
With your if statement;

If (Request.QueryString("accesslevel") <> "") Then
  rsUsers__MMColParam = Request.QueryString("accesslevel")
End If

You are saying, "show me all the users that have an access level that is not empty or null and have an access level of the value of the variable 'accesslevel'", which you defined as having a value of 1 with the assignment;

rsUsers__MMColParam = "1".

You are setting the SQL statement to search the database for users  that have that value using the variable rsUsers_MMColParam;

rsUsers.Source = "SELECT * FROM qryUser_Admin WHERE userLevelID = " + Replace(rsUsers__MMColParam, "'", "''") + " ORDER BY lname ASC"

To get what you want you need to change the SQL statement to get all of your users regardless of what their access level is;

rsUsers.Source = "SELECT * FROM qryUser_Admin ORDER BY lname ASC"

This says select everything from the qryUser_Admin table and sort it by the field lname in ascending order.

At this point you won't need your if statement at the top of your page.
0
 

Author Comment

by:polaatx
ID: 11751134
Thanks for your response.

So then how do I filter my data? The reason I created the if statement and the accesslevel querystring was so I can filter the user according to their accesslevel.

What is the procedure for creating filters, like the links I have on top of the page: http://aasg.brinkster.net/admin/user_admin.asp?Submit2=Delete

thanks.
0
 
LVL 8

Accepted Solution

by:
alexhogan earned 500 total points
ID: 11751842
OK.., I see.

You were close the first time.  You just need to modify the statement a little.  Instead of using an if statement use a case.

Select Case Request.QueryString("accesslevel")

   Case 0
       Set rsUsers = Server.CreateObject("ADODB.Recordset")
       rsUsers.ActiveConnection = MM_connSane1_STRING
       rsUsers.Source = "SELECT * FROM qryUser_Admin ORDER BY lname ASC"
       rsUsers.CursorType = 0
       rsUsers.CursorLocation = 2
       rsUsers.LockType = 1
       rsUsers.Open()
       rsUsers_numRows = 0
   Case Else
      Set rsUsers = Server.CreateObject("ADODB.Recordset")
      rsUsers.ActiveConnection = MM_connSane1_STRING
      rsUsers.Source = "SELECT * FROM qryUser_Admin WHERE userLevelID = " + Replace(rsUsers__MMColParam, "'", "''") + " ORDER BY lname ASC"
     rsUsers.CursorType = 0
     rsUsers.CursorLocation = 2
     rsUsers.LockType = 1
     rsUsers.Open()
     rsUsers_numRows = 0
  End Select

You can have a value for each of the case statements that represent your passed valued.  Just pass the url param like you were doing before.  Be sure to assign a 0 to the All users link.
0
 

Author Comment

by:polaatx
ID: 11753356
Thanks alexhogan,

Your solution works.

So, just for your own learning: this select case statement is the typical way to setup sort and filter scenarios?

I mean whenever I want sort or filter functions, I simply create separate recordsets containing those scenarios and then plug them into select case statements. Correct?

I am just wondering if there is an easier or more common method.

thanks again.
0
 
LVL 8

Expert Comment

by:alexhogan
ID: 11753664
A select case statement allows you to set up multiple conditions in an orderly code block.  If you didn't use the case statement you'd be using an if..elseif..else statement and that can get extremely busy and hard to read.

The case statement allows you to easily add additional contiditions, and branching code within those conditions.

For filtering try to identify the most common thread between them that you can simply replace variable values to change the outcome.  From there you will create the additional scenarios that you need.

Remember the idea is to code once and reuse as much as possible.

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question