Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 23rd, 2007, 02:42 PM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP Arrays

Hi,

I have a data input form that enables user's to conduct searches on my database.

I am trying to make it so they can have any selection of the fields to run their query.

I thought the best way would be to put the entries from the form into an array, take out all the not null values and put them into an sql query.

Currently I have tried using a single array with just the values, but found I couldn't specify columns in my where clause without knowing what values are not null. To rectify this I tried using a multidimensional array to hold both the field name as it appears in the database, and the value from the form.

I am inexperienced with asp, and I am having problems with extracting the not null values from the array, and I have only vague ideas of how to put them into an sql query.

This is my code:
Code:
<%
var varMemberid = Request.form("memberid");
var varCountry = Request.form("country");
var varCity = Request.form("city");
var varProptype = Request.form("proptype");
var varBeds = Request.form("beds");
var varAccom = Request.form("accom");
var varSmoke = Request.form("smoke");
var varChild = Request.form("child");
var varPets = Request.form("pets");
var varAvail = Request.form("availability");
var varDit = Request.form("dit");
var varpercent = Request.form("percent");
var vardoubledit = Request.form("2dit");
var varsqlstring = "SELECT * FROM tbl_Member M, tbl_Home H WHERE M.MemberID = H.tbl_MemberID ";  

var MyArray = new Array(1,9) //declaring a multidimensional array with 2 cols (0, 1) and 10 rows (0-9)
MyArray (0,0) = "MemberID" //enter first variable into the array
MyArray (1,0) = "Country"
MyArray (2,0) = "City"
MyArray (3,0) = "PropertyType"
MyArray (4,0) = "NoBedrooms"
MyArray (5,0) = "NoCanAccommodate"
MyArray (6,0) = "SmokingNon"
MyArray (7,0) = "ChildrenPermitted"
MyArray (8,0) = "PetsPermitted"
MyArray (9,0) = "Availability" //here and above the variables are identical to the field names in tbl_Home
MyArray (0,1) = varMemberid
MyArray (1,1) = varCountry
MyArray (2,1) = varCity
MyArray (3,1) = varProptype
MyArray (4,1) = varBeds
MyArray (5,1) = varAccom
MyArray (6,1) = varSmoke
MyArray (7,1) = varChild
MyArray (8,1) = varPets
MyArray (9,1) = varAvail //these are the variables from above
//UBound(MyArray) to find the highest element in the array
for (a=0; UBound(MyArray,1);a++){

}
All of my code in in HTML and JavaScript, and I can't use any other language.
Any help (or ideas of a simpler way) would be much appreciated!
 
Old February 23rd, 2007, 05:04 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

It would seem that your whole search thing would be much easier if you had all of the variables in drop-down menus, radio buttons and check boxes. Then you could build your SQL query dynamically. Something like:

SQL = "SELECT * FROM [tablename] WHERE 1 = 1 "
If varCountry <> "" Then
SQL = SQL + " AND Country = '" & Trim(varCountry) & "' "
End If
If varCity <> "" Then
SQL = SQL + " AND City = '" & Trim(varCountry) & "' "
End If

And list all of the rest of your variables to build your SQL statement.

???



 
Old February 23rd, 2007, 06:26 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I agree with Rich here, it would be easier to just append values based upon form input rather then looping through an array which can get messy.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 24th, 2007, 04:14 AM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much for your help, could I just ask, what is the purpose of having the Trim() function?

 
Old February 24th, 2007, 12:08 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

It removes leading and trailing white space charaters from a string.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 25th, 2007, 05:21 AM
Registered User
 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou very much for your help, it is hugely appreciated.

 
Old February 25th, 2007, 11:57 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

no problem, glad you got it all worked out.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending arrays to ASP chrscote Classic ASP Basics 1 July 22nd, 2005 07:02 PM
Urgent: Pagination in ASP using arrays ,code reqd. jyoti_khera BOOK: Beginning ASP 3.0 1 October 19th, 2004 12:25 PM
Searching ASP Arrays higgsy Classic ASP Basics 0 June 24th, 2003 05:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.