Location: PHPKode > scripts > Tabs Links SQL > tabs-links-sql/index.php
<?php

include "config.php";
include "header.php";

// Catches the link value
$paglinks = @$_GET["paglinks"];

// If no value, page = 1
//if(!isset($paglinks)) {
//$paglinks = 1; 
//}
// Determine initial variable values
if(!$paglinks){ 
	$prevnext = "1";
	} else { 
	$prevnext = $paglinks;
}
$inicial = $prevnext - 1;
$inicial = $inicial * $porpagina;

// Consults limit per page
$consulta = "select * from $tabelabd order by $ordem $direcao limit $inicial,$porpagina";
$resultado = mysql_query($consulta) or die("Cannot connect to BD");

// Consult to total number of Links / Pages
$consulta2 = "select * from $tabelabd order by $ordem";
$resultado2 = mysql_query($consulta2) or die("Cannot connect to BD");

$totallinks = mysql_num_rows($resultado2);
$totalpaginas = ceil($totallinks/$porpagina);	

// Shows total links and pages
echo "</td></tr><tr><td height='40' valign='middle' align='center'>";
echo "<font face='verdana,arial' size='2'>Total: $totallinks link(s) in $totalpaginas page(s)</font>";
echo "</td></tr><tr><td valign='top'>";

echo "<table border='0' width='430' height='150'>";

// Toggle asc (0) or desc (1)
$contaasc = $inicial+1;
$contadesc = $totallinks - $inicial;

switch ($contaascdesc){

case "0":
$contador = $contaasc;
// Catches the values from BD
while ($linha = mysql_fetch_array($resultado)) {
	$id = $linha["id"];
	$data = $linha["data"];
	$nome = $linha["nome"];
	$descricao = $linha["descricao"];
	$link = $linha["link"];
	
// Create table lines
 echo "
<tr><td width='50%'><font face='verdana,arial' size='2'>$contador | </font><a href='$link' target='_blank' class='tabslinks'><font face='verdana,arial' size='2'>$nome</a> - $descricao</font></td></tr>$linhatabela";
$contador++;
}
break;

case "1":
$contador = $contadesc;
// Catches the values from BD
while ($linha = mysql_fetch_array($resultado)) {
	$id = $linha["id"];
	$data = $linha["data"];
	$nome = $linha["nome"];
	$descricao = $linha["descricao"];
	$link = $linha["link"];

 echo "
<tr><td width='50%'><font face='verdana,arial' size='2'>$contador | </font><a href='$link' target='_blank' class='tabslinks'><font face='verdana,arial' size='2'>$nome</a> - $descricao</font></td></tr>$linhatabela";
$contador--;
}
break;

default:
echo "Counting error";
break;
}

if ($totallinks == "0"){
echo "$naocadastro <br>";
}
echo "</table>";

echo "</td></tr><tr><td height='30' valign='bottom'>";
//Foot pagination
echo "<table border='0' width='430'><tr><td align='center'>";
$prevlink = $prevnext - 1;
$nextlink = $prevnext + 1;
if ($prevnext == 1){
echo "<font face='verdana' size='2' color='#555555'>Prev</font> ";
}
//Create the prev and next links
if($prevnext > 1){
	echo "<font face='verdana,arial' size='2' color='#555555'><a href='?paglinks=$prevlink'  class='tabslinks'>Prev</a></font> ";
}   

for ($i=1;$i<($totalpaginas + 1); $i++){
	if($i==$paglinks){
		echo " <b><font face='verdana,arial' size='2'>$i</font></b> ";
	} else {
	echo " <font face='verdana,arial' size='2' color='#555555'><a href='?paglinks=$i' class='tabslinks'> $i </a></font> "; 
	}
}

if($prevnext < $totalpaginas){
	echo " <font face='verdana,arial' size='2' color='#555555'><a href='?paglinks=$nextlink' class='tabslinks'>Next </a></font>";
}
// Ends creation of links
if ($prevnext == $totalpaginas){
echo " <font face='verdana,arial' size='2' color='#555555'>Next</font>";
}
echo "</td></tr></table>";
include "footer.php";
?>
Return current item: Tabs Links SQL