| Author |
Topic Search Topic Options
|
kennywhite
Groupie
Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
|
Post Options
Thanks(0)
Quote Reply
Topic: How Can I Create A Permalink? Posted: 02 April 2009 at 2:25pm |
Hello.
I have a page where database entries are displayed. I would like to create a link so that I can click on each entry to diplay all of the data from the entry seperately.
Like the permalink that you can click on here:
Thanks!
|
 |
kennywhite
Groupie
Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 May 2009 at 3:58pm |
I've looked a lot and I can't find anything on the net that can tell me how to do this.
It is a pretty common function, so I must be missing something.
Can anyone help me figure out how to do this or give me a good link for helpful reading?
Thanks!
|
 |
Scotty32
Moderator Group
Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 May 2009 at 7:24pm |
If you know ASP it is very simple. you make your link point to say:
site.com/details.asp?id=1 |
1 should be replaced with the unique ID from the database, you then grab it in the page doing:
<% intID = Request.QueryString("id") %> |
and grab the information from your database like so:
<% strSQL = "SELECT * FROM tblTable WHERE id = " & intID & ";" %> |
Obviously this will need expanding and customising to fit your specific needs.
|
|
|
 |
kennywhite
Groupie
Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 May 2009 at 8:50pm |
Thanks for the example, but forgive me for I am a noob. I was hoping that I did this right, but apparently I did not.
Here is the page I made. It is details.asp
I have a list of assets on one page and then when I click on one it will take me to this page with ?id=X at the end. X would be the ID of whichever entry I click on, of course.
The exapmles that you have given me are marked in red below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html> <head> <title>Assets - Indianapolis</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../reports/simpleBlog.css" rel="stylesheet" type="text/css" /> <link href="styles/drop_down.css" rel="stylesheet" type="text/css" /> <link href="styles/menu5.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="white" text="black">
<% 'Dimension variables Dim adoCon 'Holds the Database Connection Object Dim rsAsset 'Holds the recordset for the records in the database Dim strSQL 'Holds the SQL query to query the database
'Create an ADO connection object Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("assets.mdb")
'Create an ADO recordset object Set rsAsset = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database DESCending order strSQL = "SELECT assets.DeviceType, assets.Make, assets.Model, assets.Serial, assets.Asset,
assets.Department, assets.SiteCode, assets.User, assets.Condition, assets.Notes, assets.ID_no
FROM assets WHERE id = " & intID & ";"
%>
<%intID = Request.QueryString("id")%>
<% Response.Write (rsAsset("Make"))%>
<% Response.Write (rsAsset("Model"))%>
<% Response.Write (rsAsset("Serial"))%>
|
What have I done wrong?
|
 |
Scotty32
Moderator Group
Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
|
Post Options
Thanks(0)
Quote Reply
Posted: 18 May 2009 at 10:06pm |
You have placed the request for the id AFTER you have tried to use it. You need to move the Request.QueryString("id") to the top of the page (after the first line) Also, you may need to change "id" in the SQL statement to "ID_no" if this is your ID field (autonumber). Also, for added security to prevent SQL Injection hacking attempts you may wish to use the following instead:
<% intID = Request.QueryString("id") if isNumeric(intID) then intID = clng(intID) else intID = 0 %> |
|
|
|
 |
kennywhite
Groupie
Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
|
Post Options
Thanks(0)
Quote Reply
Posted: 19 May 2009 at 3:16pm |
I'm still not able to get this to work.
I changed the auto number field in the database to "ID" to make this a little easier.
Here is my code now.
< %@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <% intID = Request.QueryString("id") if isNumeric(intID) then intID = clng(intID) else intID = 0%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html> <head> <title>Assets</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../reports/simpleBlog.css" rel="stylesheet" type="text/css" /> <link href="styles/drop_down.css" rel="stylesheet" type="text/css" /> <link href="styles/menu5.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="white" text="black">
<% 'Dimension variables Dim adoCon 'Holds the Database Connection Object Dim rsAsset 'Holds the recordset for the records in the database Dim strSQL 'Holds the SQL query to query the database
'Create an ADO connection object Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("assets.mdb")
'Create an ADO recordset object Set rsAsset = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database DESCending order strSQL = "SELECT assets.DeviceType, assets.Make, assets.Model, assets.Serial, assets.Asset,
assets.Department, assets.SiteCode, assets.User, assets.Condition, assets.Notes, assets.ID FROM assets WHERE id = " & intID & ";"
'Open the recordset with the SQL query rsAsset.Open strSQL, adoCon
%>
<% Response.Write (rsAsset("Make"))%> <% Response.Write (rsAsset("Model"))%> <% Response.Write (rsAsset("Serial"))%>
<%
rsAsset.Close Set rsAsset = Nothing Set adoCon = Nothing %>
|
|
 |
Scotty32
Moderator Group
Joined: 30 November 2002
Location: Manchester, UK
Status: Offline
Points: 1682
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 May 2009 at 6:07pm |
The second line needs to be on different lines, just as I posted it. Also, if you continue to get errors it would be easier if you posted the error you get. If you are just getting a standard "Page cannot be displayed" error you may need to read about HTTP 500 - Internal server error and how to turn off friendly http errors, to get to the real error.
|
|
|
 |
kennywhite
Groupie
Joined: 26 February 2009
Location: Indy
Status: Offline
Points: 106
|
Post Options
Thanks(0)
Quote Reply
Posted: 22 May 2009 at 2:39pm |
Oops, I had originally put that into two lines, but I must hit the delete key by mistake or something...
Still doesn't work, though.
Here is the error message that I am getting. It seems to be a problem with my SQL statement.
Error Type: Microsoft VBScript compilation (0x800A0409) Unterminated string constant /assets/details.asp, line 39, column 91 strSQL = "SELECT assets.DeviceType, assets.Make, assets.Model, assets.Serial, assets.Asset,
Thanks for helping!
|
 |