Page Navigation by php



The following code is useful to navigate pages in ur site. Works only for PHP Sites. U must have MySQL.

<?php
session_start();
mysql_connect(localhost,”root”,”cs”) ;  //username=root, password=cs
mysql_select_db(“mysite”);
$id=explode(“/”,$_SERVER[‘SCRIPT_NAME’]);
$id=array_reverse($id);
$id=explode(“.”,$id[0]);
$i=0;
try
{
@mysql_query(“create table mysite.p (path varchar(45),n integer)”);
}
catch{}
$j=mysql_numrows(mysql_query(“select * from mysite.p”));
$qr=mysql_query(“select * from mysite.p where path='”.$id[0].”‘”);
$y=mysql_numrows($qr);
if ($y==0)
{
$x=$j+1;
mysql_query(“insert into mysite.p(path,n) values(‘”.$id[0].”‘,”.$x.”)”);
}
else
{
$x=mysql_result($qr,$i,”n”);
mysql_query(“delete from mysite.p where n>”.$x);
}
$k=mysql_query(“select * from mysite.p”);
$h=mysql_numrows($k);
$e=0;
while ($i<$h)
{
if ($id[0]!=”home”)
{
$z=mysql_query(“select * from mysite.path where path='”.mysql_result($k,$i,”path”).”‘”);
echo “<a href=\””.mysql_result($k,$i,”path”).”.php?a=”.$_SESSION[‘type’].”\”>”.@mysql_result($z,$e,”name”).”</a>”;
echo “>”;
}
$i++;
}
?>
The table path must contain the name displayed according to filename of pages. filename means Ex. srijon.php. Here filename=srijon
mysite is my database
Advertisements