Forums

ASP

This topic is locked

Fliter male, female or all in recordset?

Posted 27 Jul 2007 11:51:12
1
has voted
27 Jul 2007 11:51:12 Ryan Preece posted:
Hi all,

I've been looking around the net for a tutorial on this but so far unsuccessful!

I have a page on a community based site I'm working on where users will need to be able
to filter a group of other users. I can get around this the long way but would love to know
the correct way to do it.

imagine a page showing all users. I want 2 options for filtering.. 1 is gender and the other is by
they're star sign.

To keep it simple I would really like to know first off how I can filter by the gender.

I can filter male / female that bit is easy but if I wanted to show all - how do I achieve that?

I have:

SELECT *
form tbl_name
WHERE gender = MMColParam

the MMColParam containing the variable passed from a list menu!

is there something I can put in the list menu as a value for all that will get me the result I'm after.

I noticed on a tutorial some time ago (and I'm searching for now) where the author put something like:

male = WHERE gender = male
female = WHERE gender = female

as the values...

This is based on my example obviously - the tutorial was for something else.

Can I do something similar only leaving the value of all empty?

any help would be appreciated as I've just overcomplicated it now!

thank you

Replies

Replied 01 Aug 2007 19:49:55
01 Aug 2007 19:49:55 dave blohm replied:
this is how I would do it...

<pre id=code><font face=courier size=2 id=code>
&lt;%
var_sql =""
' ::::: USING THE POST METHOD WITH YOUR FORM :::::
if request.form("gender" &lt;&gt; "" then
var_sql = " where gender = " & cstr(request.form("gender"
end if
' ::::: USING THE GET METHOD WITH YOUR FORM :::::
'if request.querystring("gender" &lt;&gt; "" then
' var_sql = " where gender = " & cstr(request.form("gender"
'end if

' ::::: IF A GENDER IS PASSED THEN WE APPEND THE 'WHERE'
' ::::: STATEMENT TO THE END OF THE SQL STATEMENT. IF NO
' ::::: VALUE IS PASSED FOR GENDER THEN WE JUST LEAVE THE SQL
' ::::: STATEMENT AS IS TO GRAB ALL RECORDS

Set rs_tutorial_cmd = Server.CreateObject ("ADODB.Command"
rs_tutorial_cmd.ActiveConnection = MM_conn_cellnet_STRING
rs_tutorial_cmd.CommandText = "SELECT * FROM dbo.cit_utilities_list" & var_sql
Set rs_tutorial = rs_tutorial_cmd.Execute
var_sql = ""

%&gt;

</font id=code></pre id=code>

Hope this helps...



- Doc

Progress is made by the discontent.

Reply to this topic