PDA

View Full Version : Click a Hyperlink to submit data to the same page


BradYB
07-18-2008, 11:52 AM
Hi, I'm sure this is a basic to anyone with a bit of nouse, and I even think I've done it myself in the past, but I can't remember how.

The aim:
I have a page (logoffstats.asp) which produces a list of names and statistics tied to those names (a count of closed incidents for each person).

I would like to click the name (in the form of a hyperlink) and this would cause a list of those incidents to appear beneath.

I'm presuming I use the FORM Method=POST to the same page name, and then the hyperlink contains pagename.asp?who=personsname.

So far I've got this code:


<form method="POST" action="logoffstats.asp">
<table>
<%
Do While Not objrs.EOF
%>
<tr>
<td>
<%
'response.write sqlstr
whoended = objrs("ENDEDBY")
howmany = objrs("CountOfREFNO")
%>

<a href="logoffstats.asp?who=<%=objrs("ENDEDBY")%>"><%=objrs("ENDEDBY")%></a>


<%response.write howmany %>
</td>
</tr>
<%
objrs.movenext
Loop
objrs.close


%>
</form>


and I've hit a wall as to where to go next. Any help greatly appreciated.

abduraooft
07-18-2008, 12:09 PM
Please follow http://www.codingforums.com/showthread.php?t=82672 on how to post code in this forum. (You may edit your recent posts)

BradYB
07-18-2008, 12:22 PM
Thanks abduraooft. I've edited the original post to make it (hopefully) clearer to understand.

M@rco
07-19-2008, 12:15 PM
You're going about it correctly building a URL for each link which contains the parameter "who" populated with ENDEDBY from your recordset.... although without knowing more I wonder whether ENDEDBY is unique for each user - are you storing something like a USERID field which you can pass as a parameter instead?

Anyway, what I don't see is any logic that's going to pick up that parameter when the link is followed and retrieve whatever data you intend to display about the selected user. I suggest you think of this as two different pages - one to list them all, one to render data for the clicked user. It's the latter page that seems entirely absent at present. I suggest that you prototype it with all the fields/tables/whatever in place with dummy values, then wire it up to data from a database query which retrieves the desired data.

And why do you think you need the <form> element if you're using <a> hyperlinks?

BradYB
07-21-2008, 11:55 AM
Yes, I see what you mean. I've over complicated things by using a Form and have used the request.querystring method in the second half of my page to receive the consultant ID (Yes, ENDEDBY is a set of initials that represent each team member).

The second half of the page displays data extracted via an SQL string that puls all the problems ended where the consultant is the initials received from the top half of the page and in last week's week number.

Looks to be working, albeit slowly so now I just need to work out what's taking so long to pull the data.

Thanks for your help M@rco.

M@rco
07-21-2008, 09:15 PM
Yes, I see what you mean. I've over complicated things by using a Form and have used the request.querystring method in the second half of my page to receive the consultant ID (Yes, ENDEDBY is a set of initials that represent each team member).

Beware, this is pretty classic blunder, initials aren't very unique at all, ALWAYS use an identifier that is 100% guaranteed to be unique (such as the record number of the parent table you are cross-referencing against) - in this case you should pass the autonumber UserID field from your User table (or equivalent). If you don't have a record like this (i.e. that the database populates itself automatically when you add a new record) then you should have!

The second half of the page displays data extracted via an SQL string that puls all the problems ended where the consultant is the initials received from the top half of the page and in last week's week number.

Looks to be working, albeit slowly so now I just need to work out what's taking so long to pull the data.

A query like "SELECT * FROM UserLog where UserLog.UserID=12272 ORDER BY TimeStamp" (which is what I presume you're doing here) should be a triflingly simple task for ANY database (even with hundreds of thousands of records) so the results should be pretty much instant - if they're not then you've done something wrong.

Check whether it's the query that is taking the time, or the rendering in the rest of your ASP script. Also note that matching numeric fields (e.g. UserID) is MUCH quicker than comparing strings (as the DB will have to do if you're looking up initials instead)...

Perhaps copy & paste your SQL statement here and I'll take a look at it...?

Thanks for your help M@rco.
You're welcome! :thumbsup: