Below are TWO fragments of PHP code... The first one is for YOUR main script, that will do the DataBase quries, and the second one are two functions which build a gliding navigation bar!!! If u use this, please give some credit to me and my work http://www.ita-studio.com
If something doesnt work, mail me, and I will fix it... But this script I use at all my sites 🙂
<?php
$toshow = 20; //how many results per page
$sql = mysql_query("SELECT * FROM sometable");
$t = mysql_query($sql);
$m = mysql_num_rows($t);
if($block > $m){
$block = $m - $toshow;}
if ($temp = mysql_fetch_array($t)){
mysql_data_seek($t, $block);}
if($res = mysql_fetch_array($t)){
for($i=0;$i<$toshow;$i++){
//YOUR CODE HERE...
if($res = mysql_fetch_array($t)){
} else { break; }
}
if($m > $toshow){
echo "<br>";
// this outputs the navigation bar... make sure you replace the name of the file below from index.php
// to wherever this script is running from
echo show_line($m, $toshow, rebuild("index.php", $HTTP_GET_VARS), $block);}
} else {
echo "<b>Sorry, nothin found... 🙁 </b><br>";
}
?>
<?php
/*
This function will rebuild any GET variables passed to a page
in the form of a link. Eg. adverts.php?dir=12&cir=13 will be
constructed from $curr being 'adverts.php' and $vars being the
global $HTTP_GET_VARS array.
Version: 0.8
Purpose: To use in the Shortcut Nav Bar generation.
*/
function rebuild($curr, $vars){
$s = sizeof($vars);
$t = $curr;
$t .= "?";
if($s>0){
for($i = 0; $i<$s; $i++)
{
if(key($vars)=="block"){
next($vars);
continue;
}
$t .= key($vars) . "=";
$t .= current($vars);
$t .= "&";
if(($i+1)<$s){
next($vars);
}
}
}
return $t;
}
/*
This fucntion will create the actual short cut navigation bar
based on the parameters passed to it. $max represents the max
number of elements to be accessed in the database, $div is the
step at which the line will operate, $link is most frequently
$php_self but any link can be specified, and finally $b is the
current block, to make the current selection stand out.
Version: 2.0
Purpose: To use in the Shortcut Nav Bar generation.
Updates from V 1.0 - Sliding Bar, shows 7 entities, and "slides"
the middle on request. All placed inside pretty tables.
*/
function show_line($max, $div, $link, $b){
$rep = ceil($max / $div);
if($rep < 2){
}else{
$currentposition = round($b / $div);
if($currentposition<3){
$minis = 0;
$maxis = 5;
} else {
$minis = $currentposition - 2;
$maxis = $currentposition + 3;
}
if($maxis > $rep){
$maxis = $rep;
$minis = $maxis - 5;
if($minis < 0){$minis = 0;}
}
$perc = round(100/($maxis - $minis + 2));
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"#880000\"><tr>";
echo "<td><table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\"><tr>";
if($b>0){
//print previous
$temp = $b - $div;
echo "<td bgcolor=\"#FFefef\" width=$perc%><div align=center class=small><b>";
printf ("<a href=\"$link%s=$temp\">Zurück</a>","block");
echo "</b></div></td>";
}
for($i = $minis; $i<$maxis; $i++){
$temp = $i * $div;
$t = $i + 1;
$tm = $t*$div - $div + 1;
$tc = $t*$div;
if($tc > $max){
$tc = $max; }
if(round($b / $div)==$i){
echo "<td bgcolor=\"#FFC1C1\" width=$perc%><div align=center class=small><b>$tm - $tc</b></div></td>";
} else {
echo "<td bgcolor=\"#FFefef\" width=$perc%><div align=center class=small><b>";
printf ("<a href=\"$link%s=$temp\">%s - %s</a>", "block",$tm,$tc);
echo "</b></div></td>";
}
} //end for
if($b<($max-$div)){
//print next
$temp = $b + $div;
echo "<td bgcolor=\"#FFefef\" width=$perc%><div align=center class=small><b>";
printf("<a href=\"$link%s=$temp\">Weiter...</a>","block");
echo "</b></div></td>";
}
echo "</tr></table></td></tr></table>";
}
}//end function
?>