Re: Creating 'Previous - Next Buttons' Logic - Novice Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




""Daniel Brown"" <parasane@xxxxxxxxx> wrote in message news:ab5568160706151411k48e08445xb3323820e9037b87@xxxxxxxxxxxxxxxxx
On 6/15/07, revDAVE <coolcat@xxxxxxxxxxxxxxxx> wrote:
Novice Question: I would like to create a set of pages that could use some kind of logic to have "previous - next buttons "so that when the button was clicked it would automatically go to the next page - or the previous page.

I know very little about PHP ...  however, I am hoping that there is some
kind of preset " open source" php code that I might be able to use.

I can envision something like this:

- An 'include page' that might store an array of the list of pages such as:


start array...

pos1 = page1.htm
pos2 = page17.htm
pos3 = page5.htm
etc.....

stop array...

- then  a variable could be set for the current page such as:


thispage = 2  - Place on the array equals position 2 (page17.htm)


then the next button would add 1 to the current place on the array- (pos3)


-  and the previous button would be minus 1 place on the array - (pos1)

... that type of thing

Q: Is there any "open source" code template that I can check out like this?




--
Thanks - RevDave
CoolCat@xxxxxxxxxxxxxxxx
[db-lists]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



There are several ways to do this, but here's one way:

<?
$page[] = "page1.htm";
$page[] = "page17.htm";
$page[] = "page5.htm";
// Or you can do:
// $page = array('page1.htm','page17.htm','page5.htm');

session_start(); // For storing the user's current position

if(!$_GET['page_num']) {
   $i = 0;
}

if($i != 0) {
   echo "<a href=\"".$page[($i - 1)]."\">&lt;&lt; Previous</a>\n";
}

if($i != (count($page) - 1)) {
   echo "<a href=\"".$page[($i + 1)]."\">Next &gt;&gt;</a>\n";
}

include('page'.$i.'.htm');
?>

--
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107


Totally would work for his purposes but let's clean it up a bit for a beginner.

<?
$page = array('page1.htm','page17.htm','page5.htm'); // array of the pages you have

if(isset($_GET['page_num'])) // a current page number has been set in the url
{
$i = $_GET['page_num'];  // set variable i to the current page number
if($i != (count($i)-1)) // if the current page number isnt the last entry in the array display next
   echo "<a href=\"".$page[($i + 1)]."\">Next &gt;&gt;</a>\n";
if($i != 0) // if the current page isn't the first page display previous
       echo "<a href=\"".$page[($i - 1)]."\">&lt;&lt; Previous</a>\n";
}
include('page'.$i.'.htm');  // show the current page you're at
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux