ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

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 Dev Shed Forums Sponsor:
  #1  
Old September 24th, 2003, 08:02 AM
Pain Pain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Sheffield, UK
Posts: 94 Pain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to Pain
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>

Reply With Quote
  #2  
Old September 24th, 2003, 09:23 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
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:
 where ( OR 
which is TSQL syntatically incorrect. I'd uncomment the response.write strSQL line so you can see what your end product is.

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....

Reply With Quote
  #3  
Old September 25th, 2003, 04:00 AM
Pain Pain is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Sheffield, UK
Posts: 94 Pain User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to Pain
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

Reply With Quote
  #4  
Old September 25th, 2003, 12:53 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Integrating asp into a table to auto generate rows from a select statement


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 4 hosted by Hostway