Author Topic: Previous next buttons  (Read 2769 times)

0 Members and 1 Guest are viewing this topic.

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Previous next buttons
« on: October 15, 2007, 09:21:09 AM »
Hi. I'm using the extra script and have created a list to show. In this list there is an open window function to display more details in a new window. Question: how can I create a link or button to allow me to jump to the next record [[ID]] in the same open window and click forward and backwards through all the records? Have you done something like that before? Thanks Casi

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Previous next buttons
« Reply #1 on: October 15, 2007, 03:30:41 PM »
Casi,

You can do it with javascript assuming you have the auto ID turned on, and you haven't used any of the random number hacks:

This js will take you back one record:
Code: [Select]
<script>
var a = [[ID]]
b = --a
document.write("<a href='http://www.yourdomain.com/cgi-bin/csvread.pl?ID=" + b + "'>Back</a>")
</script>

This js will take you forward one record:
Code: [Select]
<script>
var a = [[ID]]
b = ++a
document.write("<a href='http://www.yoursite.com/cgi-bin/csvread.pl?ID=" + b + "'>Next</a>")
</script>

Have fun!

Jason

Founder of www.slipdex.com

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Re: Previous next buttons
« Reply #2 on: October 16, 2007, 03:45:09 AM »
Jason

Thanks a lot - works fantastic!

Cheers
Casi

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Re: Previous next buttons
« Reply #3 on: October 25, 2007, 01:31:11 AM »
Jason, i tested the script with only 8 entries in the db... with more entries the script does not work propper anymore, as it shows ID 1 and 11 and 12 and 13 etc. on the same page the same time (all ID starting with a 1 - then the same fault with all ID staring with a 2 and so on... can you help? Thanks Casi.

Offline Paul

  • Hero Member
  • *****
  • Posts: 162
Re: Previous next buttons
« Reply #4 on: October 25, 2007, 05:47:50 AM »
I think there may be a problem with the variable names being repeated.

Try this...it might work

Code: [Select]
<script>
var a[[ID]] = [[ID]]
document.write("<a href='http://www.yourdomain.com/cgi-bin/csvread.pl?ID=" + --a[[ID]] + "'>Back</a>")
</script>



Code: [Select]
<script>
var b[[ID]] = [[ID]]
document.write("<a href='http://www.yoursite.com/cgi-bin/csvread.pl?ID=" + ++b[[ID]] + "'>Next</a>")
</script>

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Previous next buttons
« Reply #5 on: October 25, 2007, 06:52:14 AM »
Casi,

I don't see why Paul's script won't work, but just so everyone knows, you can repeat variable names as long as they are in separate script tags.

I copied my prev and next buttons directly from my source, so they do work.  It may be that you are using ID that start in single digits.  If you use the auto ID feature in the script it will work.  If you give me a link to your pages I can maybe see if there is an error somewhere.

Jason
Founder of www.slipdex.com

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Re: Previous next buttons
« Reply #6 on: October 25, 2007, 07:59:55 AM »
Jason, Paul

I copied the files to a temporary test subdomain and will leave them for a few days. The orignal files are protected.

Please be aware that all is in german. Please use the following link to access the page:

http://5.casi.ch/cgi-bin/a_r_radsatzliste.pl?order_by=ID&order=321

The red icon to the right will open a new window showing the selected record only. please select any one and then you see to the right on top the links in german (« vorheriger Eintrag  | nächster Eintrag ») (previous | next). Please click through the records. As soon as they get a singel ID number the script fails.

Something else, when the script reaches the last ID it looses the ID and shows (ID=NaN). Therfore I placed a link in csvread to go back to the main list (Ende der Einträge - zurück zur Radsatzliste.). Is there a better way to solve this as well?

Thanks for your help, Casi

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Re: Previous next buttons
« Reply #7 on: October 25, 2007, 08:08:42 AM »
Jason

I do use the auto ID in the script csvwrite:

##########################################################
# Advanced Settings auto ID 
my $ID_autoincrement         = 1;
my $ID_autoincrement_name    = "ID";
##########################################################

The ID's in my database start with single digits
ID|
1|
2|
3|
4|
5|
6|
7|
8|
9|
10|
11|
12|

Thanks Casi

Offline Jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 1018
    • slipdex
Re: Previous next buttons
« Reply #8 on: October 25, 2007, 01:51:35 PM »
Casi,

I see why it is doing it.  Add method=perfect to your previous and next javascripts.  What is happening, since you started at single digit ID's the previous and next buttons are pulling any record with the single digit in it.  So if you try going previous to ID 1 then you get 1, 11, 10, 21...  any record that has a one.  This is why you should start the auto ID at the default 1000000.  But use method=perfect and that should do it, or better still for future issues, reset all the ID to use the defult start of 1000000, it's really better.

As for reaching the end of the records and getting the Nan, which is the javascript null value, there is not really good way to avoid it other than changing the js by hand to not show a link that goes passed the last record if you have a finite number of records.  If users continue to add records, you may be in a tough coding spot.

Jason
Founder of www.slipdex.com

Offline Paul

  • Hero Member
  • *****
  • Posts: 162
Re: Previous next buttons
« Reply #9 on: October 25, 2007, 07:07:10 PM »
Nice pick up Jason,

Thanks for that info on the variable names.

Offline casi

  • Jr. Member
  • **
  • Posts: 34
Re: Previous next buttons
« Reply #10 on: October 26, 2007, 12:56:17 AM »
Jason, Paul

Thanks for your great support! By the way, I'm a big fan for the EZ scripts and have used them in many websites and they are simply FANTASTIC!

Casi