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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Next Thread" mechanism in ASP

Status
Not open for further replies.

perryair

IS-IT--Management
Apr 7, 2005
91
IL
Hello..
I've got query page that pull records from SQL database,
when I click on each record that shown on the screen
it send me to another page that shows the record
in view mode..
I would like to create 2 buttons that shows the last record and next record as like the "Next Thread" that can be found on this website..

Please advice..
 
OK try something like this...
Code:
<form>
<input type="button" value="Previous Record" name="B1" onclick="return OnButton1();"> 
<input type="button" value="Next Record" name="B2" onclick="return OnButton2();">
</form>
[blue]
<script language=javascript>
<!--
function OnButton1()
{
	document.Form1.action = "viewrecord.asp?recordId=Session("recordId")-1"
	document.Form1.target = "_top";
        document.Form1.submit();
        return true;
}

function OnButton2()
{
	document.Form1.action = viewrecord.asp?recordId=Session("recordId")+1"
	document.Form1.target = "_top";
        document.Form1.submit();
        return true;
}
-->
</script>
[/blue]

The above is just to give you an idea...you need to tweak it to your requirements...

post back if you have any more questions...

-DNG
 
Links/buttons must point to the same page with two GET variables: threadID and location (equivalent to qid and nx on this site). First one determines "reference" thread ID, second is about location (allowed values "next", "last" or empty).

Current forum can be found via threadID (I guess in DB/table that would be foreign key column in table Threads pointing on table Forums). Once you determine current forum logic depends on location value:

- empty: target thread is reference thread (as identified ny threadID)
- "next": target thread is next thread within current forum
- "last": target thread is last thread within current forum

Next/last ID can be found with MIN()/MAX and simple WHERE clause, assuming that new threads always have greater PK value (identity/autonumber?).

Now you have ID of target thread to display and the rest is simple.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Thanks DotNetGnat, it seems to be work fine but I have a little problem..
When I click on one of the options, I see that it doesn't take the rest of the JS code, which is
'recordId=Session("recordId")-1"'
on the address bar I can see only the following:
'
If I type the rest of the code manually in the address bar it seems to be work good as I wish..


Any idea?
 
the code after the ? is just an example code...you need to change it to fit your variable names...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top