Can Any body help with this script. I am not an expert in PHP
I am displaying images 4 each in a page and the last image is repeating. unset is not working.
<?php
$ar=scandir("hairupdo");
$n=0;
$h="hairupdo";
$cnt=0;
$numofimages=count($ar)-3;
$imagesperpage=4;
$numberofimages=0;
$pages=ceil ($numofimages/$imagesperpage );
$gid=$_GET["id"];
echo "<table width=100 border=0 cellspacing=5 cellpadding=5>";
echo "<tr>";
for($i=1; $i<=$pages ;$i++)
{
echo "<a href=viewhairupdo.php?id=$i a>$i ";
}
while(list($key,$ars)=each($ar))
{
echo "dollar n : $n";
if (file_extension($ar[$key])=="jpg"||file_extension($ar[$key])=="jpeg")
{
if ($cnt==2 )
{
echo "</tr><tr>";
echo "<td>";
}
else
{
echo "<td>";
}
echo "<img src=hairupdo/$ar[$n]>";
echo "</td>";
$cnt=$cnt+1;
}
if ($n<count($ar)-1)
{
$n=$n+1;
}
if ($cnt==4 )
{
break;
}
}
function file_extension($filename)
{
return end(explode(".", $filename));
}
?>