Re: i need ur help about pagenation

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

 



Hi Kashi,

I used this on my site, made a few modifications,( hope i dint miss
out any details)so here is:

<?php
$hostname='localhost';
$user='username';
$pass='password';
$dbase='database';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die
("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select
database.");

/// Variables
$WHERE = "WHERE department = 'Engineering' AND Hostel = 'St Loius' ";
/// Your sql statement
$max_results = 5; /// Number of results per page

if(!isset($_GET['pg'])){ $pg = 1; } else { $pg = $_GET['pg']; } 
$from = (($pg * $max_results) - $max_results); 

/// Count total
$totals = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM
faculties $WHERE "),0); 
$total_pgs = ceil($totals / $max_results);

/// Page limiter & result builder
$sql = "SELECT * FROM faculties $WHERE LIMIT $from, $max_results";
$result1 = mysql_query($sql); $num_sql = mysql_num_rows ($result1);

echo "Results: $totals <br>";
echo "Viewing page $pg of $total_pgs<br>";

// Build paginator 
if($pg > 1){ $prev = ($pg - 1); // Previous Link 
$paginator ="<a href="".$_SERVER['PHP_SELF']."?pg=$prev">"Previous
page</a>"; } 
for($i = 1; $i <= $total_pgs; $i++){ /// Numbers
if(($pg) == $i) { $paginator .= "<i>$i</i> "; } else { 
$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$i">$i</a> "; }} 
if($pg < $total_pgs){ $next = ($pg + 1); // Next Link 
$paginator .="<a href="".$_SERVER['PHP_SELF']."?pg=$next">"Next
page."</a>"; }

echo "$paginator<br><br>";

/// Display results
if ($num_sql > 0 ) {$i=0;
while ($i < $num_sql) {
$mysite = mysql_result($result1,$i,"mysite");
echo "$mysite<br>";
++$i;}}

echo "<br>$paginator";
?>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux