|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Integrating asp into a table to auto generate rows from a select statement
Hi guys,
Im running a select statement to a database and wish to display the relevant records into a table. For some reason, its not liking this - can someone see why, and or tell me an easier way to produce an 'automatically generating' table of results. Cheers guys! Chris <% @language="vbscript" %> <% Option Explicit %> <% Response.Buffer=True %> <html> <head> <title>Search Results</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FFFFFF" text="#000000"> <!-- #include file="dbConn.asp" --> <!-- #include file="adovbs.inc"--> <h1>Your search results returned the following popup messages:</h1> <% Dim msgtype, title, message, url msgtype=request.form("type") title=request.form("title") message=request.form("msg") url=request.form("URL") Dim adoDB, adors, strSQL set adoDB = Server.CreateObject("ADODB.Connection") adoDB.Open strConnection set adoRS = Server.CreateObject("ADODB.RecordSet") strSQL="SELECT PID,P_TITLE,P_MSG,P_URL,P_TYPE FROM POPUP WHERE (" If msgtype <> "" then strSQL=strSQL & "P_TYPE='" & msgtype & "' " If title <> "" then strSQL=strSQL & "OR P_TITLE LIKE '%" & title & "%' " If message <> "" then strSQL=strSQL & "OR P_MSG LIKE '%" & message & "%' " If url <> "" then strSQL=strSQL & "OR P_URL LIKE '%" & url & "%' " End if strSQL=strSQL & ")" 'DEBUG ONLY!! 'response.write strSQL 'response.end adoRS.Open strSQL, adoDB ' Loop through the recordset to display the records Do While Not adoRS.EOF & " <tr> " & & " <td> " & Response.Write adoRS.Fields("PID").Value & " </td> " & " <td> " & Response.Write adoRS.Fields("P_TYPE").Value & " </td>" & " <td> " & Response.Write adoRS.Fields("P_TITLE").Value & "</td>" & " <td> " & Response.Write adoRS.Fields("P_MSG").Value & "</td>" & " <td> " & Response.Write adoRS.Fields("P_URL").Value & "</td></tr>" adoRS.MoveNext Loop & " </table> " & ' Tidy up afterwards adoRS.Close Set adoRS = Nothing adoDB.Close Set adoDB = Nothing %> </body> </html> |
|
#2
|
|||
|
|||
|
you need to give more information than "it doesn't like it" next time please
You have problems because you have conditional ifs that execute only if it's true, then lets say the first is false, the next part is putting PHP Code:
i tend to not do conditionals and just put like '%%' even if it's blank because that's the same as leaving it out of the statement, but it depend if tha tcolum has stuff like pete, petel, peteq and the such where pete would return all of them.... |
|
#3
|
|||
|
|||
|
Thanks for the reply.
I understand your point about the conditional If statements, and realise that the user has what may seem the opportunity to throw a spanner into the works. However, on the form itself, I intend to include some script such that the user must complete certain fields for searching, and hence will alleviate the syntaxical problems that may occur. However, to clarify, my problem is not with the SQL, but rather the mixing up of asp and html to generate the results into a table. Ive seen some methods that will do something like: <table> <tr> <td><% response.write(resp1) %></td> <td><% response.write(resp2 %></td> </tr> </table> and ive seen others do it like how im doing it above. However, I seem to be uncomfortable using either, and was hoping someone can point me in the right direction for approaching it correctly with a view to let the asp generate the correct size of table given the results that are returned (something which the evample i've done here wont do). Chris |
|
#4
|
|||
|
|||
|
Where is your beginning <table> ???
A good way to look at the results is to do a VIEW/SOURCE and look at the html result. This way you'll know if your code is correct. Now try something like: <% . . . . . . adoRS.Open strSQL, adoDB 'Beginning of the html <table> Response.Write "<table>" & vbcrlf Do While Not adoRS.EOF Response.Write "<tr>" & vbcrlf Response.Write "<td>" & adoRS.Fields("PID").Value & "</td>" & vbcrlf Response.Write "<td>.... Response.Write "</tr>" & vbcrlf adoRS.MoveNext Loop 'End of the html <table> Response.Write "</table>" & vbcrlf . . . . . . %> Hope this helps! Sincerely Vlince Last edited by Vlince : September 25th, 2003 at 12:57 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Integrating asp into a table to auto generate rows from a select statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|