Hi friends
I have developed the small function for navigaion of record set
Its looks like Yahoo navigation bar
if any body wants totest it please test it and send me the feedback if found any error
IT WILL LOOK LIKE
showing 1 of 100 [ Previous | Next | First | Last ]
Variable Help :
PAGE_SIZE = No fo records you want to display on the page e.g you can give 10 or any number
$filename : File name on which you are useing it
$params = which buit the query string to make posted varible exists
write it like This
$params = "a=$n&b=$c&c=$d" // its a string which builts the query string.....
rest of variables are easy to understand
function preNavigation()
{
global $start,$nav,$pages1,$last;
if($last==1)
return $start = $pages1 * PAGE_SIZE -1;
if($last==2)
return $start = 0;
if($start==null)
return $start=0;
if($nav==2)
return $start = $start + PAGE_SIZE;
if($nav==1)
return $start = $start - PAGE_SIZE;
}
function postNavigation($filename,$params,$pages1,$start,$records)
{
if($pages1==1)
echo "<div align=center> Showing ".($start + 1)." - ".($start + PAGE_SIZE)." of ".$records." [ Previous | Next | First | Last ]</div>";
if($start==0)
echo "<div align=center> Showing ".($start + 1)." - ".($start + PAGE_SIZE)." of ".$records." [ Previous | <a href='".$filename."?".$params."&nav=2&start=".$start."&pages1=".$pages1."'>Next</a> | First | <a href='".$filename."?".$params."&last=1&pages1=".$pages1."'>Last</a> ]</div>";
if($start>0 && $start <($records-PAGE_SIZE)) //=
echo "<div align=center> Showing ".($start + 1)." - ".($start + PAGE_SIZE)." of ".$records." [ <a href='".$filename."?".$params."&nav=1&start=".$start."&pages1=".$pages1."'>Previous</a> | <a href='".$filename."?".$params."&nav=2&start=".$start."&pages1=".$pages1."'>Next</a> | <a href='".$filename."?".$params."&last=2&pages1=".$pages1."'>First</a> | <a href='".$filename."?".$params."&last=1&pages1=".$pages1."'>Last</a> ]</div>";
if($start >=($records-PAGE_SIZE))
echo "<div align=center> Showing ".($start + 1)." - ".$records." of ".$records." [ <a href='".$filename."?".$params."&nav=1&start=".$start."'>Previous</a> | Next</a> | <a href='".$filename."?".$params."&last=2&pages1=".$pages1."'>First</a> | Last ]</div>";
}
/How to call the function /
//-------------------------------------------------------
preNavigation(); //Just call it here before querying
//-----------------------------------------------------------------
$result1=sql_select("SELECT * FROM ".T_CATEGORY);
/sql select is function written by me which return result set you can hard code it /
$result=sql_select("SELECT * FROM ".T_GROUP." WHERE CAT_ID = '$catid' limit ".$start." , " .PAGE_SIZE);
$records= mysql_num_rows($result1); //no of records retrive form the query
$pages1 = floor($records/PAGE_SIZE); //no fo pages = records/no of records on one page
echo "<table class=".$tclass.">";
echo "<tr class=".$tclass.">";
echo "<td class=".$tclass.">";
echo "<font class=".$fclass.">Group Listings</font>";
echo "</td>";
echo "<tr class=".$tclass.">";
echo "<td class=".$tclass.">";
//--------------------------------------------------------------------
postNavigation("showgroups.php",$params,$pages1,$start,$records);
/ called after querying /
//----------------------------------------------------------------------
echo "</td>";
echo "</tr>";
while($row = mysql_fetch_object($result))
{
echo "<tr class=".$trclass.">";
echo "<td class=".$tdclass.">";
$groupname = $row->GROUP_NAME;
$directlink = $row->DIRECT_LINK;
$description = $row->DESCRIPTION;
$groupid = $row->GROUP_ID;
/*group name links to that group*/
echo "<a class=".$linkclass." href=".$directlink.">".$groupname."</a> ". getMembersCount($groupid) ."<br>";
/*description of the group*/
echo $description;
echo "</td>";
echo "</tr>";
}
echo "<tr class=".$trclass.">";
echo "<td class=".$tdclass.">";
$params = "&catid=".$catid;
//--------------------------------------------------------------------
postNavigation("showgroups.php",$params,$pages1,$start,$records);
//--------------------------------------------------------------------
echo "</td>";
echo "</tr>";
echo "</table>";