|
 |
asp_databases thread: Need help adding a database search to a hyperlink
Message #1 by "Frode Strømme" <fstroemm@o...> on Tue, 24 Apr 2001 16:01:41
|
|
I search my movie database for a certain movie title. The database table
have a field called ID and a field called Title.
How would I go forward to write a response line like this:
http://www.whatever.com/display.asp?ID=100
Where this hyperlink is displayed with name of the Title from database.
Pressing this link will display more information about that movie, with
help of the ID query.
Here's what I started at:
Response.Write "<A HREF=""display.asp"">Click</A>"
ID=100 needs to be added to display.asp, and Click needs to be the name of
the retured movie match.
Here is my search code. Tell me if there's something else wrong too. I'm
not an expert:
<%
Dim searchStr, MyConn, RS, i
searchStr = Replace(Request.Form("strSearch"), "'", "''")
Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)};
DBQ=C:\datastores\movietest.mdb"
SQL = "SELECT * FROM moviebase WHERE moviebase.Title "
SQL = SQL & "LIKE '%"&searchStr&"%' "
Set RS = MyConn.Execute(SQL)
If searchStr <> "" Then
If RS.BOF AND RS.EOF Then
Response.Write "<center>No Records found matching your
search.</center>"
Else
Response.Write "</tr>"
While Not RS.EOF
Response.Write "<tr>"
For i= 1 to RS.Fields.Count - 1 ' Starts at title field
' Here is where some changes needs to be done to make it a hyperlink
Response.Write "<td>" & RS("Title") & "</td>"
Next
Response.Write "</tr>"
RS.MoveNext
WEND
Response.Write "</table>"
End If
Else
Response.Write "<center>You need to write a search string.</center>"
End IF
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
%>
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Tue, 24 Apr 2001 11:22:46 -0400
|
|
There is no need for the extra For..Next loop. It should look
something
like this instead:
While Not RS.EOF
Response.Write "<tr><td>"
Response.Write "<a
href=3D'http://www.whatever.com/display.asp?ID=3D" &
Server.URLEncode(RS("ID")) & "'>" & Server.HTMLEncode(RS("Title")) &
"</a>"
Response.Write "</td></tr>"
RS.MoveNext
WEND
> -----Original Message-----
> From: Frode Str=F8mme [mailto:fstroemm@o...]
> Sent: Tuesday, April 24, 2001 4:02 PM
> To: ASP Databases
> Subject: [asp_databases] Need help adding a database search to a
> hyperlink
>
>
> I search my movie database for a certain movie title. The
> database table
> have a field called ID and a field called Title.
>
> How would I go forward to write a response line like this:
>
> http://www.whatever.com/display.asp?ID=3D100
>
> Where this hyperlink is displayed with name of the Title from
> database.
> Pressing this link will display more information about that
> movie, with
> help of the ID query.
>
> Here's what I started at:
> Response.Write "<A HREF=3D""display.asp"">Click</A>"
>
> ID=3D100 needs to be added to display.asp, and Click needs to
> be the name of
> the retured movie match.
>
> Here is my search code. Tell me if there's something else
> wrong too. I'm
> not an expert:
>
> <%
> Dim searchStr, MyConn, RS, i
>
> searchStr =3D Replace(Request.Form("strSearch"), "'", "''")
>
> Set MyConn=3DServer.CreateObject("ADODB.Connection")
>
> MyConn.Open "Driver=3D{Microsoft Access Driver (*.mdb)};
> DBQ=3DC:\datastores\movietest.mdb"
>
> SQL =3D "SELECT * FROM moviebase WHERE moviebase.Title "
> SQL =3D SQL & "LIKE '%"&searchStr&"%' "
>
> Set RS =3D MyConn.Execute(SQL)
>
> If searchStr <> "" Then
> If RS.BOF AND RS.EOF Then
> Response.Write "<center>No Records found matching your
> search.</center>"
> Else
> =09
> =09
> Response.Write "</tr>"
> While Not RS.EOF
> Response.Write "<tr>"
> For i=3D 1 to RS.Fields.Count - 1 ' Starts at
> title field
>
> ' Here is where some changes needs to be done to make it a
hyperlink
>
> Response.Write "<td>" & RS("Title") & "</td>"=09
>
> Next
> Response.Write "</tr>"
> RS.MoveNext
> WEND
> Response.Write "</table>"
> End If
>
> Else
> Response.Write "<center>You need to write a search
> string.</center>"
>
> End IF
>
> RS.Close
> MyConn.Close
> Set RS =3D Nothing
> Set MyConn =3D Nothing
> %>
>
Message #3 by "Charles Feduke" <webmaster@r...> on Tue, 24 Apr 2001 16:09:13 -0400
|
|
Try:
Response.Write("<A HREF=""display.asp?title=" & RS("Title") & """>Click</A>")
When passing by this method, you need to use Request.QueryString("item")
rather than Request.Form("item") as you are getting data from the querystring
and not the form.
- Chuck
----- Original Message -----
From: "Frode Strømme" <fstroemm@o...>
To: "ASP Databases" <asp_databases@p...>
Sent: Tuesday, April 24, 2001 4:01 PM
Subject: [asp_databases] Need help adding a database search to a hyperlink
> I search my movie database for a certain movie title. The database table
> have a field called ID and a field called Title.
>
> How would I go forward to write a response line like this:
>
> http://www.whatever.com/display.asp?ID=100
>
> Where this hyperlink is displayed with name of the Title from database.
> Pressing this link will display more information about that movie, with
> help of the ID query.
>
> Here's what I started at:
> Response.Write "<A HREF=""display.asp"">Click</A>"
>
> ID=100 needs to be added to display.asp, and Click needs to be the name of
> the retured movie match.
>
> Here is my search code. Tell me if there's something else wrong too. I'm
> not an expert:
>
> <%
> Dim searchStr, MyConn, RS, i
>
> searchStr = Replace(Request.Form("strSearch"), "'", "''")
>
> Set MyConn=Server.CreateObject("ADODB.Connection")
>
> MyConn.Open "Driver={Microsoft Access Driver (*.mdb)};
> DBQ=C:\datastores\movietest.mdb"
>
> SQL = "SELECT * FROM moviebase WHERE moviebase.Title "
> SQL = SQL & "LIKE '%"&searchStr&"%' "
>
> Set RS = MyConn.Execute(SQL)
>
> If searchStr <> "" Then
> If RS.BOF AND RS.EOF Then
> Response.Write "<center>No Records found matching your
> search.</center>"
> Else
>
>
> Response.Write "</tr>"
> While Not RS.EOF
> Response.Write "<tr>"
> For i= 1 to RS.Fields.Count - 1 ' Starts at title field
>
> ' Here is where some changes needs to be done to make it a hyperlink
>
> Response.Write "<td>" & RS("Title") & "</td>"
> Next
> Response.Write "</tr>"
> RS.MoveNext
> WEND
> Response.Write "</table>"
> End If
>
> Else
> Response.Write "<center>You need to write a search string.</center>"
>
> End IF
>
> RS.Close
> MyConn.Close
> Set RS = Nothing
> Set MyConn = Nothing
> %>
|
|
 |