PHP Classes

previous and next button

Recommend this page to a friend!

      pn_buttons  >  All threads  >  previous and next button  >  (Un) Subscribe thread alerts  
Subject:previous and next button
Summary:how to create prev and next button to access data from maxdb
Messages:2
Author:ambarisha kn
Date:2008-01-22 13:32:38
Update:2008-01-24 04:22:09
 

  1. previous and next button   Reply   Report abuse  
Picture of ambarisha kn ambarisha kn - 2008-01-22 13:32:39
I want create previous and next button to display the row from database, one after another when click on previous and next button. I have maxdb database. Please help me regrding this problem. I found so many scripts for mysql, but It was not able me to change for maxdb.. Please give me the script for maxdb queries..

  2. Re: previous and next link using MAXDB...   Reply   Report abuse  
Picture of ambarisha kn ambarisha kn - 2008-01-24 04:22:09 - In reply to message 1 from ambarisha kn
I did previous and next links using maxdb queries. It may helpful to those who are using maxdb databse.


<?php
$page = $_GET['page'];
$server = "localhost";
$user = "DBADMIN";
$pass = "NICHI";
$databasename = "MAXDB1";
$db = maxdb_connect($server, $user, $pass, $databasename);
maxdb_autocommit($db, true);

$sql = "SELECT * FROM example ORDER BY id";
$query = maxdb_query($db,$sql);
$total_results = maxdb_num_rows($query);


$limit = "1"; //limit of archived results per page.
$total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
{
$page = "1"; //default page if none is selected

}
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB


echo $page.' '.$offset;

$query = "SELECT * FROM example ORDER BY id limit $offset $limit ";
$result = maxdb_query($db,$query);


//This is the start of the normal results...

while ($row = maxdb_fetch_array($result))
{
// display your results as you see fit here.
echo $row['ID']." ".$row['TITEL']." &nbsp; ".$row['URL']."<br>";

}
maxdb_close();


// This is the Previous/Next Navigation
echo "<font face=Verdana size=1>";
echo "Pages:($total_pages)&nbsp;&nbsp;"; // total pages
if ($page != 1)
{
echo "<a href=$PHP_SELF?page=1><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
$prevpage = $page - 1;
echo "&nbsp;<a href=$PHP_SELF?page=$prevpage><<</a>&nbsp;"; // Previous Page Link
}
if ($page == $total_pages)
{
$to = $total_pages;
}
elseif ($page == $total_pages-1)
{
$to = $page+1;
}
elseif ($page == $total_pages-2)
{
$to = $page+2;
}
else
{
$to = $page+3;
}
if ($page == 1 || $page == 2 || $page == 3)
{
$from = 1;
}
else
{
$from = $page-3;
}

for ($i = $from; $i <= $to; $i++)

{
if ($i == $total_results) $to=$total_results;
if ($i != $page)
{
echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
}
else
{
echo "<b><font face=Verdana size=2>[$i]</font></b>";
}
if ($i != $total_pages)
echo "&nbsp;";
}
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo "&nbsp;<a href=$PHP_SELF?page=$nextpage>>></a>&nbsp;"; // Next Page Link
echo "&nbsp;&nbsp;&nbsp;<a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link
}
echo "</font>";

// This is the end of the Previous/Next Navigation

?>