weronpc
04-07-2003, 05:20 PM
Hello
I created a php script, it will get the info from mysql and display it.
My question is, I only want to disply 5 records at the time, user have to click next to view 5 more and so on....
I know how to disply all of them at once, but 5 at the time???
Can someone please help me.
Thank you in advance,
Mike
missing-score
04-07-2003, 07:33 PM
This is what I do for my forum:
$x = 1;
if($threadAmmount > 5)
{
echo '<span id="nameDescrip">Pages: </span>';
if(($_GET['start']-5) >= 0)
{
echo '<a class="arrows" href="page.php?&start='.($_GET['start']-5).'"><</a> ';
}
for($i = 0; $i < $threadAmmount; $i+=5)
{
if($_GET['start'] != $i)
{
echo ' <a class="arrows" href="page.php?&start='.$i.'">'.$x.'</a> ';
$x++;
}
else
{
echo ' <span id="nameHeading">[ '.$x.' ] </span> ';
$x++;
}
}
if(($_GET['start']+5) < $threadAmmount)
{
echo ' <a class="arrows" href="page.php?start='.($_GET['start']+5).'">></a>';
}
}
It passes the start through a variable called start ( $_GET['start']; )
$limit = 0;
$query = mysql_query("SOME QUERY");
for($i = 1; $row = mysql_fetch_array($query); $i++)
{
if($limit >= 5)
{
break;
}
else
{
if($i == 0 && $i == $_GET['start'] || $i > $_GET['start'])
{
// Do Whatever with the info
$limit++;
}
}
}
That makes sure you only display the files wanted.
This system also makes a next and back system like on my forum (http://forums.itk-network.com)
[ 1 ] 2 3 4 >
Hope this helps.