Click to See Complete Forum and Search --> : Selecting a set of data


Redhead
12-12-2004, 12:46 PM
Hi There

I was wondering how or where i can find out how to have a next and previous buttons as the bottome of my php page after i pull out the data,

meaing, say i have 50 items images and discripts of dogs. what i want to do is have the first 10 show and at the bottom of those 10 have a button that says next 10 and show that set of ten. and so on. allow the user to see 10 at a time. in sted of have all 50 in a list what i have know any ideas??

MstrBob
12-12-2004, 01:23 PM
<?php
// Array Containing your descriptions. However many there are.
$descriptions=array('Yellow Dog', 'Blue Dog', '20ft Tall dog', 'Flying Dog');
// Counts the amount of descriptions
$count=count($descriptions);
// Checks that the pic variable is set, that it is an increment of 10
// and that it isn't larger than the amount of descriptions
if(!empty($_GET['id'])&&!is_float($_GET['id']/10)&&$_GET['id']<$count)
{
$start=$_GET['id'];
} else {
// If the id variable isn't set, or is invalid, start at the beginning
$start=0;
}
// cycle through 10 times
for($x=$start;$x<($start+10);$x++)
{
// If $x is less than the amount of descriptions, echo the description
if($x<$count)
{echo('<p>'.$descriptions[$x].'"</p>'."\n");}
}
// If you can subtract 10, and it's greater than 0, echo a back button
if(($start-10)>=0)
{echo('<a href="?id='.($start-10).'">Back</a>');}
// If adding ten to our current position is less than the amount of descriptions,
// echo a next button.
if($x<$count)
{echo('<a href="?id='.$x.'">Next</a>');}
?>


Edited for your needs.

Genixdeae
12-12-2004, 01:27 PM
in google type in

paging php

you'll get tones of pages that will descripe how to make paging. or if you have Dreamweaver, do paging(with the snippets) and you can then fix up dreamweaver's code to fit your needs.