SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 15th, 2004, 11:38 PM
seanwest seanwest is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 25 seanwest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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)

Reply With Quote
  #2  
Old August 16th, 2004, 02:25 PM
mwalts's Avatar
mwalts mwalts is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Victoria, BC Canada
Posts: 482 mwalts User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 30 sec
Reputation Power: 5
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

Reply With Quote
  #3  
Old August 16th, 2004, 05:03 PM
seanwest seanwest is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 25 seanwest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
VB6? sounds like a disease any help for someneo that just knows html and asp?

thanks
Sean

Reply With Quote
  #4  
Old August 16th, 2004, 05:55 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Those examples are pretty much the same as you would do it in ASP.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > SQL Query help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT