?
Solved

Trying to get Dreamweaver to filter data

Posted on 2004-08-08
5
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 19 hours left to enroll

770 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