|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Query help
How can i make it so if the user submits a form
and there is nothing chosen (* is used) that it pulls up everything ? Im trying to make * a wildcard in the option value of the form, but it isnt working. I figure its the same as "user = * " from below mySQL = "SELECT top 1000 * FROM members where user = * AND state = '" & State & "' ORDER BY user_timestamp DESC" Id like for it to work so if they do a search from a mulitple search form ( say 4 drop boxes) and they do not select all choices, that the <OPTION value="*">Select User Type - will send a wildcard (*) that will mean the same as ALL since im using the AND command i have to make sure every field of the search is in use. so a wildcard seems to be the simple answer if possible. The form and results page sql line are below. please help if you can! search form page: <form method="GET" action="search.asp"> Show Only: <SELECT name="user" class=menutext> <OPTION value="*">Select User Type <OPTION value="basic">basic</OPTION> <OPTION value="advanced">advanced</OPTION> </SELECT> <SELECT name="State" class=menutext> <OPTION value="*">Select User Type <OPTION value="Ca">California</OPTION> <OPTION value="etc">Etc, you get the idea</OPTION> </SELECT> search results with sql statement: mySQL = "SELECT top 1000 * FROM members where user = * AND state = '" & State & "' ORDER BY user_timestamp DESC" (in this statement both user and state must be recieved or no results are given, i want results for which ever are received regardless) |
|
#2
|
||||
|
||||
|
I suggest you start building the mySQL in parts, break it up further into myWHERE as well
Then you have something like this: if not User = "" and not User = "*" then myWHERE = myWHERE & " AND user = '" & User & "'" end if now only if there is a value for user that isn't * will it add that part of the where clause, so otherwise you will get it for all users. do the same with the rest of the fields then at the end just replace the first and myWHERE = replace (myWHERE, "AND", "WHERE",,1) mySQL = "SELECT top 1000 * FROM members" & myWHERE & "you get the idea" examples done in VB 6, might need to convert to match your language |
|
#3
|
|||
|
|||
|
VB6? sounds like a disease
any help for someneo that just knows html and asp?thanks Sean |
|
#4
|
||||
|
||||
|
Those examples are pretty much the same as you would do it in ASP.
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SQL Query help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|