473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using ASP to process drop-down box data into SQL statement

Hello folks, I don't know what they've done to the ordinary ASP newsgroup, I
hope you can answer this question. I am trying to make this piece of code:

If Len(Trim(primary))=0 Then
SQL(1)="Spice = '" & spice & "' And Type = '" & dish_content & "'"
ElseIf Len(Trim(spice))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "' And Type = '" & dish_content
& "'"
ElseIf Len(Trim(dish_content))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "' And Spice = '" & spice & "'"
ElseIf (Len(Trim(primary)) And Len(Trim(spice)))=0 Then
SQL(1)="Type = '" & dish_content & "'"
ElseIf (Len(Trim(spice)) And Len(Trim(dish_content)))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "'"
ElseIf (Len(Trim(primary)) And Len(Trim(dish_content)))=0 Then
SQL(1)="Spice = '" & spice & "'"
Else SQL(1)="Primary_Dish_Type = '" & primary & "' And Spice = '" & spice &
"' And Type = '" & dish_content & "'"
End If

Return records when I select more than one ANY on the drop-down boxes from
this form:

<form method="post" action="OnLineShop.asp">
<table>
<td>Primary Dish Type?
<select name="primary">
<option value="" selected>ANY</option>
<option value="Starter">Starter</option>
<option value="Main Course">Main Course</option>
<option value="Accompaniments">Accompaniments</option>
</select></td>
<td>Spice?
<select name="spice">
<option value="" selected>ANY</option>
<option value="None">None</option>
<option value="Mild">Mild</option>
<option value="Medium">Medium</option>
<option value="Medium+">Medium+</option>
<option value="Medium or Hot">Medium or Hot</option>
<option value="Hot">Hot</option>
<option value="Very Hot">Very Hot</option>
</select>
<!-- <input name="txtData" type="text" id="txtData"> -->
</td>
<td>Dish Content?
<select name="dish_content">
<option value="" selected>ANY</option>
<option value="Vegetarian">Vegetarian</option>
<option value="Vegetable">Containing Vegetables</option>
<option value="Mushroom">Mushroom</option>
<option value="Prawn">Prawn</option>
<option value="King Prawn">King Prawn</option>
<option value="Chicken">Chicken</option>
<option value="Lamb">Lamb (general)</option>
<option value="Keema">Keema</option>
<option value="Mixed">Mixed</option>
<option value="Fish">Fish</option>
<option value="Dairy">Dairy</option>
<option value="Chicken Tikka">Chicken Tikka</option>
<option value="Lamb Tikka">Lamb Tikka</option>
<option value="Tandoori King Prawn">Tandoori King Prawn</option>
</select></td>
<td><input type="submit" name="Submit" value="Go"></td>
</p>
</table>
</form>

Have I missed something from that code?
Nov 19 '05 #1
1 2564
Your IF statement is only processing one potential ANY. A better way to
process this situation (with much less code and future flexibility) is to
build your WHERE clause as you go:

if primary<>"" then sql=sql & " primary_dish_type='" & primary & "' AND"
if spice<>"" then sql=sql & " spice='" & spice & "' AND"
if dish_content<>"" then sql=sql & " type='" & dish_content & "' AND"
if right(sql,3)="AND" then sql=left(sql,len(sql)-3)

The last IF will trim off the trailing AND. I left the AND in the third
IF to make it easier if you added more conditions in your filter later.
You could just as easily remove it.

So the basic logic is that if the user picks one of more ANY values, they
are not included in the WHERE clause, otherwise the values are included.

Hope this helps.

=?Utf-8?B?S2l3aU5FVCB1ay5nZW9jaXRpZXMuY29tL2hhcm9vbm5ldD IwMDIv?=
<KiwiNET uk.geocities.com/haroonnet2002/@discussions.microsoft.com>
wrote in news:6F**********************************@microsof t.com:
Hello folks, I don't know what they've done to the ordinary ASP
newsgroup, I hope you can answer this question. I am trying to make
this piece of code:

If Len(Trim(primary))=0 Then
SQL(1)="Spice = '" & spice & "' And Type = '" & dish_content
& "'"
ElseIf Len(Trim(spice))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "' And Type = '"
& dish_content
& "'"
ElseIf Len(Trim(dish_content))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "' And Spice = '"
& spice & "'"
ElseIf (Len(Trim(primary)) And Len(Trim(spice)))=0 Then
SQL(1)="Type = '" & dish_content & "'"
ElseIf (Len(Trim(spice)) And Len(Trim(dish_content)))=0 Then
SQL(1)="Primary_Dish_Type = '" & primary & "'"
ElseIf (Len(Trim(primary)) And Len(Trim(dish_content)))=0 Then
SQL(1)="Spice = '" & spice & "'"
Else SQL(1)="Primary_Dish_Type = '" & primary & "' And Spice = '"
& spice &
"' And Type = '" & dish_content & "'"
End If

Return records when I select more than one ANY on the drop-down boxes
from this form:

<form method="post" action="OnLineShop.asp">
<table>
<td>Primary Dish Type?
<select name="primary">
<option value="" selected>ANY</option>
<option value="Starter">Starter</option>
<option value="Main Course">Main Course</option>
<option value="Accompaniments">Accompaniments</option>
</select></td>
<td>Spice?
<select name="spice">
<option value="" selected>ANY</option>
<option value="None">None</option>
<option value="Mild">Mild</option>
<option value="Medium">Medium</option>
<option value="Medium+">Medium+</option>
<option value="Medium or Hot">Medium or Hot</option>
<option value="Hot">Hot</option>
<option value="Very Hot">Very Hot</option>
</select>
<!-- <input name="txtData" type="text" id="txtData"> -->
</td>
<td>Dish Content?
<select name="dish_content">
<option value="" selected>ANY</option>
<option value="Vegetarian">Vegetarian</option>
<option value="Vegetable">Containing Vegetables</option>
<option value="Mushroom">Mushroom</option>
<option value="Prawn">Prawn</option>
<option value="King Prawn">King Prawn</option>
<option value="Chicken">Chicken</option>
<option value="Lamb">Lamb (general)</option>
<option value="Keema">Keema</option>
<option value="Mixed">Mixed</option>
<option value="Fish">Fish</option>
<option value="Dairy">Dairy</option>
<option value="Chicken Tikka">Chicken Tikka</option>
<option value="Lamb Tikka">Lamb Tikka</option>
<option value="Tandoori King Prawn">Tandoori King
Prawn</option>
</select></td>
<td><input type="submit" name="Submit" value="Go"></td>
</p>
</table>
</form>

Have I missed something from that code?


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
4
by: Josh Usovsky | last post by:
I'm setting up a watched folder using FileSystemWatcher. When I drop a small file into the watched folder, I can respond to a .Created event and process the file with other code. However, if I try...
0
by: David Morgan | last post by:
Hello I am trying to write a routine that will retrieve all the messages in my SMTP Service Drop Folder and process them one by one based on the address(es) to which the mail was sent. When...
3
by: Edwin G. Castro | last post by:
Hi, I'm new to XSLT and I'm having a hard time figuring out whether XSLT will do what I need it to do. I have a XML file with a whole bunch of <message> elements. These <message> elements...
1
by: SnakeS | last post by:
Hi, I want say if exist an Event that find out when a process has start. For example with task manager, when a new process has start , it come update into list. Thanks.
11
by: Richard Myers | last post by:
Hello Im sure many of you have seen this error message before: For us its the third time this year. This error occurs seemingly at random. I have no idea what causes it too happen. None....
0
by: Arcer P | last post by:
Non Newbie question HOW TO: Drag a file and receive notification that the target application (ex: Windows explorer) completed the drop process (move/copy/link)? 1. A Visual Basic application...
4
by: Coleen | last post by:
Hi All :-) Can anyone give me a URL where I can find a good example of code on how to create a temporary SQL table using VB.net? I've checked the Microsoft site at: ...
3
by: Greg Collins [Microsoft MVP] | last post by:
I have done a bit of research of Url Rewriting, but as yet have been unsuccessful at getting it to work well, and there are issues around what file types are supported and how much code you want to...
10
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.