Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to <a href> a variable ?

Status
Not open for further replies.

Tivoli0

MIS
Dec 7, 2001
41
0
0
IL
Hi all,

I have a very simple code that for the life of me doesn't let me do a simple a href:

Code:
--------------   snip  -----------------

    <%Do while not RS.EOF%>

	<tr BGCOLOR=&quot;#CCFFCC&quot;>
		<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><%= RS(&quot;title&quot;)%></td>
		<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><%= RS(&quot;body&quot;)%></td>
		<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><a href=<%=RS(&quot;author&quot;)%>></a></td> 
	</tr>

      <%RS.Movenext
    Loop
    %>
---------------  snip  -----------------
Can someone show/explain to me how to have the RS(&quot;author&quot;) show the author's name as a link so when I click the author's name I'll be going to a descriptive author's page?

Thanks much! -Tivoli0
 
I believe you have to do something like this:

<tr BGCOLOR=&quot;#CCFFCC&quot;>
<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><%Response.write RS(&quot;title&quot;)%></td>

I have used the way you do with the <% = something%>
but i have only used that with variables, not calling a RS.
 
Empty Anchor tags don't display...

<%Do while not RS.EOF%>

<tr BGCOLOR=&quot;#CCFFCC&quot;>
<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><%= RS(&quot;title&quot;)></td>
<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><%= RS(&quot;body&quot;)%></td>
<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><a href=&quot;<%=RS(&quot;author&quot;)%&quot;>[red]gotta have something here[/red]</a></td>
</tr>

<%RS.Movenext
Loop
%>
 
...of course, I'm assuming that RS(&quot;author&quot;) is a well-formed URL... if it's just the Authors name, then you may need some more stuff... like



<a href=&quot;/authors/<%=RS(&quot;author&quot;)%>.htm&quot;><%=RS(&quot;author&quot;)%></a>
 
Hi There

Your code should look something like this:
Code:
<td ALIGN=&quot;left&quot; valign=&quot;top&quot;><a href=&quot;ViewAuthor.asp?AuthorID=<%=rs(&quot;AuthorID&quot;)%>&quot;><%=rs(&quot;Author&quot;)%></a></td>

The href attribute needs to be the name of the page you want to link to.

The author's name should appear between the anchor tags.

Obviously I'm making the assumption here that you need to pass an ID of some kind to the next page.


The path to freedom is seldom trodden by the multitude.
 
errr...

Ok, first you need a page that will accept the authors name in order to show a description from the database of that author. We'll pretend that page is author.asp. Now since that pag expects us to pas it the name of an author, lets pass that name in the querystring. So our link would look like:
Code:
<a href=&quot;author.asp?author=<%=RS(&quot;author&quot;)%>&quot;><%=RS(&quot;author&quot;)%></a>

That gives us a link with the Authors name in it that is linked to a page that is called author.asp
The author.asp page will need to take the name from the author querystring and retrieve the data from the database for that particular author.

It's a little dangerous to use names as querystring arguments, I generally prefer to use numeric id's. The problem with a name is that it could have single quotes in it, double quotes (nickname), etc and any of these could cause us problems down the road.
-Tarwn

[sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Do you know how hot your computer is running at home? I do
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top