lordfa9 Posted August 3, 2006 Share Posted August 3, 2006 ok this is gonna be a bit long so bear with me plzwhat i need to do is to allow my sql statement to use 2 possible variable inputsFor example:SELECT * FROM A ORDER BY BWhere A and B are the variables i want the user to input before the query is run Currently, i'm using this code for that page and to define the order by clause <html><body><table border="1" width="100%" bgcolor="#fff5ee"><tr><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=subjectname">Subject</a></th><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=dategiven">Date Given</a></th><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=datedue">Date Due</a></th></tr><%if request.querystring("sort")<>"" then sort=request.querystring("sort")else sort="dategiven"end ifset conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/database.mdb"))set rs=Server.CreateObject("ADODB.recordset")sql="SELECT * FROM 1E1 ORDER BY " & sortrs.Open sql,conndo until rs.EOF response.write("<tr>") for each x in rs.Fields response.write("<td>" & x.value & "</td>") next rs.MoveNext response.write("</tr>")looprs.closeconn.close%></table></body></html> haha3.asp is the name of the script itself and 1E1 is the table namei actually tried a variant of the script where i changed the SQL statement to SELECT * FROM " & sortthen changing the table script to <table border="1" width="100%" bgcolor="#fff5ee"><tr><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=1E1">1E1</a></th><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=2E1">2E1</a></th><th align="left" bgcolor="#b0c4de"><a href="haha3.asp?sort=3E1">3E1</a></th></tr> it worked and i was able to toggle from class to class but lost the order by functionso the question is how am i going to combine both??Appreciate no comments bout the database construction, its supposed to be that way Thanks for taking the patience to read this, all help is appreciated. Sorry if i am asking a question that appears in a tutorial somewhere, a link to that tutorial would be very helpful Link to comment Share on other sites More sharing options...
tjodalv Posted August 3, 2006 Share Posted August 3, 2006 You have to send two querystring parametars, sort and table name.Your link have to be like this:<a href="haha3.asp?sort=dategiven&tblname=1E1">Link</a>and then when constructing SQL statement your sql statemant should look like this:sort = Request.QueryString("sort")tblname = Request.QueryString("tblname")strSQL = "SELECT * FROM '" & tblname & "' & ORDER BY '" & sort & "';" Link to comment Share on other sites More sharing options...
lordfa9 Posted August 7, 2006 Author Share Posted August 7, 2006 You have to send two querystring parametars, sort and table name.Your link have to be like this:<a href="haha3.asp?sort=dategiven&tblname=1E1">Link</a>and then when constructing SQL statement your sql statemant should look like this:sort = Request.QueryString("sort")tblname = Request.QueryString("tblname")strSQL = "SELECT * FROM '" & tblname & "' & ORDER BY '" & sort & "';"thx for the tip man dont really understand the sql statement though i got away with usingsql="SELECT * " & tblname & " Order BY " & sort & ""*shrugs* Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now