...

View Full Version : printing data from db as a link



VMM
08-15-2005, 09:04 AM
Hello,

I have asp program that reads information from the database and print the information to the table on a web page.

The reading happens trough a normal "do while not EOF" loop.

I have tried to make each data to a link. I mean that when the data is printed to the table, the program would also put a link to each data. When the user selects the link in the table, the program gets all of the information from the DB based on what link did the user pushed.

For example: the program gets different car marks from the db and then prints them out into a table. every mark in the table is also a link. When the user selects, for example a Toyota, the web page gets all the toyotas from the db and prints them out.

It feels like a simple problem but still I havent found a way to solve it. If somebody can give me a hint how I should proceed, please tell me.

Thank you for advance.

Cyberlord
08-15-2005, 12:07 PM
Hello,

try this:



<%
carid = request.querystring("carid")
carmark = request.querystring("carmark")
If LEN(carid) > 0 Then
select * FROM carlist where carid = '"& carid &"'"
table for car-details......
Else
If LEN(carmark) > 0 Then
select * FROM carlist where carid = '"& carid &"'"
Else
select * FROM carlist"
End If
%>
<tr><th>Car</th><th>Mark</th></tr>
<% Do While NOT RS.EOF %>
<tr><td><a href="cars.asp?carid=<%= RS("carid") %>">Fiat Panda</a></td><td><a href="cars.asp?mark=<%= RS("carmark") %>">Fiat</a></td></tr>
<% RS.Movenext
Loop

End If %>

VMM
08-18-2005, 08:59 AM
Thank you Cyberlord. Your example was perfect. It worked very well.

Bullschmidt
08-22-2005, 03:10 AM
And to open in a new window (if you ever want to do that) you could change this:

<a href="cars.asp?carid=<%= RS("carid") %>"><%= RS("carname") %></a>

To be more like this instead:

<a href="cars.asp?carid=<%= RS("carid") %>" target="new"><%= RS("carname") %></a>

Cyberlord
08-22-2005, 12:31 PM
You can improve that:

... target="cars" onclick="window.open('','cars','menubar=no,scrollbars=yes,status=no,width=550,height=580,left='+ (screen.width-550)/2 +',top='+ (screen.height-580)/2 +'')">...

glenngv
08-22-2005, 01:16 PM
<a href="cars.asp?carid=<%= RS("carid") %>" target="cars" onclick="window.open(this.href,this.target,'menubar=no,scrollbars=yes,status=no,width=550,height=580,left='+ (screen.width-550)/2 +',top='+ (screen.height-580)/2 +'').focus();return false;">

Cyberlord
08-22-2005, 01:55 PM
You dont need to specify the url again, because i have set the target by name (cars), but i think your code should also be okay.

cheers

ghell
08-22-2005, 03:12 PM
And to open in a new window (if you ever want to do that) you could change this:

<a href="cars.asp?carid=<%= RS("carid") %>"><%= RS("carname") %></a>

To be more like this instead:

<a href="cars.asp?carid=<%= RS("carid") %>" target="new"><%= RS("carname") %></a>i thought tht was sposed to be target="_blank"

if you want all links on a page to open in a new window u can also do <base target="_blank"> in the head section.. just thought id mention that since no1 ever uses <base> even though it can be prety useful

Bullschmidt
08-22-2005, 07:49 PM
i thought tht was sposed to be target="_blank"


_blank is used a lot but a user-defined name is also allowed.

Sometimes I like to use a different user-defined name so that it will be sure to open in a new window (so that the focus is sure to move to there) instead of one that has already been opened (just a matter of preference I suppose).

And good point about base...

glenngv
08-23-2005, 05:24 AM
Sometimes I like to use a different user-defined name so that it will be sure to open in a new window (so that the focus is sure to move to there)
For user-defined window target name (and if the window with that name is already opened), focus is only set if you explicitly call the focus() method. Unlike in _blank where the focus is always set to the newly opened window even without calling focus() method.

Bullschmidt
08-23-2005, 05:46 AM
Will have to play/test that a little - thanks for the info Glenn! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum