Your old code with my comments:
<?php
//function to return the 'privious' link
function previ($start,$howmany)
{
//?? isn't howmany always = 5??
if ($howmany != 0)
{
$start = $start - 5;
if ($start > 0 )
{
$previ = "<a href='allmess.php?start=$start&howmany=5'>Previous</a>";
}
elseif ($start < 0 )
{ //Is there really 3 different conditions? $start>0, $start==0, $start<0 ?
$howmany = 5 + $start;
$start = 0;
$previ = "<a href='allmess.php?start=$start&howmany=$howmany'>Previous</a>";
}
else
{ //$start==0
$previ = "<a href='allmess.php?start=$start&howmany=$howmany'>Previous</a>";
}
}
else
{
$previ = "";
}
return $previ;
}
//function to return the 'forward' link
function forw($start,$howmany,$count)
{
$start = $start + 5;
if ($start < $count )
{
$forw = "<a href='allmess.php?start=$start&howmany=5'>Forward</a>";
}
elseif ($howmany > $count )
{ // this should be $start>=$count: $howmany is always 5 or something, right?
$forw = "";
}
Else
{
$forw = "";
}
return $forw;
}
?>
//MY takes below:
function previ($start, $howmany){
$previ="";
if($start>=$howmany){
$start=$start-$howmany;
$previ = "<a href='allmess.php?start=$start&howmany=$howmany'>Previous</a>";
}
return $previ;
}
function forw($start,$howmany,$count)
{
$forw="";
if (($start + $howmany )<=$count )
{
$forw = "<a href='allmess.php?start=$start&howmany=$howmany'>Forward</a>";
}
return $forw;
}