|
-
February 23rd, 2005, 08:46 AM
#1
Hyperlinks From Database
I am writing my ASP by hand rather than using ASP.NET as that is not available to me.
I have a database in that MS-Access database is a table called links
In that table there are 4 columns:
The First is a autonumber field to act as an ID this is the Primary Key
The Second is the URL
The Thrid is the Site name
The Forth is the Information about the site
What I want to do is display the Site Name and have that text linked upto to URL and below display the Info about the site.
I have used Response.Write and can simply display the information but I can't get the Text and the URL to work together.
Can anyone help?
-
February 23rd, 2005, 11:31 AM
#2
Re: Hyperlinks From Database
What problem exactly do you have. Can you post some sample code for us to look at?
Thanks.
-
February 23rd, 2005, 11:50 AM
#3
Re: Hyperlinks From Database
Here is the code (I have just taken the code between the body tags)
Code:
<table width="100%" border="0">
<tr valign="top">
<td width="21%"><!-- #include file="nav/left.asp" --></td>
<td width="79%"><p><strong>Useful Links</strong></p>
<p><%
dim Conn
dim FilePath
dim SQL
Dim RsUser
'Connection to Database
Set Conn = Server.CreateObject("ADODB.Connection")
FilePath = Server.MapPath("db/database.mdb")
Conn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & FilePath & ";"
'SQL Query String
SQL = "Select * FROM links"
'Set the Recordset
Set RSUser = Conn.Execute (SQL)
'Print the Recordset
RSUser.movefirst
Do while not RSUser.EOF
Response.Write ("<P>")
Response.Write (RSUser("url")) 'the address of the website
response.write("<br>")
response.write (RSUser("text")) 'the title of the website
response.write("<br>")
response.write (RSUser("info")) 'info about website
Response.Write ("</a>")
Response.Write ("</p>")
RSUser.movenext
Loop
%></p>
<p> </p></td>
</tr>
</table>
<p> </p>
</body>
I understand what is wrong with the above code, it currently shows the 'url', 'text' and 'info' fields from the database and loops till all entries are shown.
Now I would like to make it so that the user only sees 'text' and 'info' and the link on 'text' is 'url' that is where I can't get it to work.
-
February 28th, 2005, 04:09 AM
#4
Re: Hyperlinks From Database
I have found it works if you store the URL without the http:// and use the below code.
Code:
RSUser.movefirst
Do while not RSUser.EOF
Response.Write ("<p>")
Response.Write ("<a href=" & chr(34) & "http://" & RSUser("url") & chr(34)& ">")
Response.Write (RSUser("text")) 'the title of the website
Response.Write ("</a>")
Response.Write ("<br>")
Response.Write (RSUser("info")) 'info about website
Response.Write ("</p>")
RSUser.movenext
Code suggested from a member of another forum.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|