Forum Moderators: coopster

Message Too Old, No Replies

Attaching prev and next buttons to php functions

         

imagus

8:01 am on Apr 15, 2003 (gmt 0)

10+ Year Member



Hi guys,
I have a search script that works ok. It shows one record at a time and displays 'next' on the first record and then 'next, 'prev' on subsequent records as you view the searched criteria one record at a time.
My problem is that I would like to attach these functions to buttons (or imgas that I can use as button.

The if statements that produce these functions are as follows:

// links to previous results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print "<a href=\"$PHP_SELF?s=$prevs&q=$var\">
PREV</a>";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

// not last page so give NEXT link
$news=$s+$limit;
//echo "<a href=\"$PHP_SELF?s=$news&q=$var\">;</a>";
echo "<a href=\"$PHP_SELF?s=$news&q=$var\"><b>¦. NEXT</b></a>";
}

thanx
imagus

jatar_k

7:39 pm on Apr 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use javascript on the buttons and write the js with php

onClick="window.location='<? echo $PHP_SELF,"?s=",$news,"&q=",$var;?>'"

I think window.location is right.

grahamstewart

12:18 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better still, you could avoid Javascript by using forms..


<form method="get" action="<?php echo $_SERVER['PHP_SELF']?>">
<input type="hidden" name="q" value="1">
<input type="submit" value="Previous">
</form>

Or you could just use normal anchor links..


<a href="<?php echo $_SERVER['PHP_SELF']?>?q=1">previous</a>
<a href="<?php echo $_SERVER['PHP_SELF']?>?q=3">next</a>

In both cases you can get the value of q by using $_GET['q']. Don't just use $q as this only works if register_globals is set on (which is usually a bad thing!).

Incidentally, if you are using this technique to link lots of pages together then you should also setup the <link> tags [w3.org] in <head>.

e.g.


<link rel="contents" rev="subsection" href="index.html">
<link rel="prev" rev="next" href="page_3.html">
<link rel="next" rev="prev" href="page_5.html">

Then users of decent browsers (like Opera) will be able to browse your pages using the browser controls. Plus search engines should index the pages better.