Killersites.com Homepage Welcome Guest   |   Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | User List  | Help



Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 8
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 2976 times and has 7 replies Next Thread
Male newbies13
Stranger




Joined: May 27, 2008
Post Count: 6
Status: Offline
Reply to this Post  Reply with Quote 
Passing a hyperlink with asp ?

I am new to using asp with mysql, I have everything set up with my database and my webpage is displaying the database information that I want. So far so good, however have now hit a snag. I will explain what I am doing to give a better description of my problem since I don't really know what the problem is.

I have a database of restaurants that I am displaying in tables, I would like to have each restaurant display as a hyperlink to further information about that specific restaurant though. And I am not sure how to go about doing that, if I can do it at all ?

So picture a big list of restaurants in a table from a database, lets say I want to see more information about McDonalds, I click mcdonalds and it then loads more in depth information about mcdonalds.

[May 27, 2008 11:44:01 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male admin
Advanced Member
Member's Avatar


Joined: Jun 14, 2003
Post Count: 2933
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Hi,

What you want to do is create what a lot of people would call a 'detail' page.

This is what you need to do:

  • In your table where you display all your records, you need to dynamically create a link with the id of a particular record inserted into the link ... for each record you pull from the database.
  • You need to create a page that grabs that id from the query string. And you use that id to make another database query to grab the other information.


For example, in your first page where you list all your records, for each record/row you would include this link:

<a href="detail-page.asp?restaurantid='<% response.write "restaurant-id" %>'">View Details</a>


Now in you 'detail' page, you need to grab that id from the query string:
<%

Request.QueryString("restaurantid")

%>


Makes sense?

Stefan
----------------------------------------
Stefan Mischook

Video Tutorial Store | Web Templates
[May 28, 2008 12:50:56 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male newbies13
Stranger




Joined: May 27, 2008
Post Count: 6
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Is it possible to pass the restaurantid to the restaurant when the page is called up ? Or do I need to create an ID by hand for each link and then use that ?

Basically as I understand it then it almost seems easier to just HTML cod the list of restaurants, since I would be hand coding each entry with an sql query via asp anyway ?
[May 28, 2008 2:27:02 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Basically as I understand it then it almost seems easier to just HTML cod the list of restaurants, since I would be hand coding each entry with an sql query via asp anyway ?


You don't need to hand code this. You can set up your restaurants table in the database to have a unique id that automatically increments:


CREATE table restaurants(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

other fields...
);


Then use a loop to loop through the restaurant table, grabbing one row at a time, and using asp get the id of each restaurant and create the link like Stef (Admin) suggested.

That link (for example, you could link to "detail-page.asp?restaurantid=1") would then send the user to the details page, which would then figure out which restaurant the user is wanting to view via the restaurantid in the URL (in this case, the restaurant with an id of 1) and display the correct information.
----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[May 28, 2008 3:07:13 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male falkencreative
Advanced Member
Member's Avatar

USA
Joined: Aug 14, 2007
Post Count: 1129
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Just as an add-on to my last reply, you may want to check out (found using a quick search on Google):

http://www.plus2net.com/asp-tutorial/sql-select.php
http://www.w3schools.com/ASP/coll_querystring.asp
----------------------------------------
Benjamin Falk | student : designer : developer
Twitter: falkencreative
[May 28, 2008 3:11:57 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male newbies13
Stranger




Joined: May 27, 2008
Post Count: 6
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Very informative thanks, Ill try some of this out and post again if I run into more problems.
[May 28, 2008 6:27:53 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male newbies13
Stranger




Joined: May 27, 2008
Post Count: 6
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Ok I had to rework the structure of my database in order to get the ID to work properly, the problem I have run into now is that my page now has blank lines in it and shows the information lopsided.

Dim oConn, oRs
Dim qry, connectstr
Dim db_name, db_username, db_userpassword
Dim db_server

db_server = "secureserver.net"
db_name = "newtest22"
db_username = "myusername"
db_userpassword = "mypassword"
fieldname = "AF"
fieldname2 = "ID"
tablename = "newtest"

connectstr = "Driver={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr

qry = "SELECT * FROM " & tablename

Set oRS = oConn.Execute(qry)

if not oRS.EOF then
while not oRS.EOF

%>
<table width="720" border="2" cellpadding="0" cellspacing="0">
<tr>
<td width="177" align="center" valign="top"><% if oRs.Fields(fieldname2) < 8 then response.write oRs.Fields(fieldname) else %></td>
<td width="177" align="center" valign="top"><% if oRs.Fields(fieldname2) > 7 then response.write oRs.Fields(fieldname) else %></td>
</tr>
</table>

This is what I am using to display the information and split it. Basically I have entered a number of restaurants, if there ID is under 8 they go on side one. If its more then 7 it goes on side 2... The problem is that side two has 7 blank lines and then starts inputting data, instead of starting at the top...

I am guessing it's due to my lack of else statement, but I can't find a code that says else remove blank line until we hit some data.
----------------------------------------
[Edit 1 times, last edit by newbies13 at May 28, 2008 8:44:14 PM]
[May 28, 2008 8:39:59 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male newbies13
Stranger




Joined: May 27, 2008
Post Count: 6
Status: Offline
Reply to this Post  Reply with Quote 
Re: Passing a hyperlink with asp ?

Also I have run into a snag with dynamic select query...

I have my restaurant page linked to my database, it queries all and puts a link on each as suggested. so now when you click on arbys it points to ?restaurantID=Arbys. My problem now is producing that in my details page, I request the querystring and try to match that up to the database so that only the arbys details are shown. But I can't seem to get it to work without specially writing arbys into my select command. Which of course results in every restaurant displaying arbys....

and SELECT * FROM doesn't seem to like dynamic content in it...
[May 29, 2008 7:26:30 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread