Hello All,
I have 2 bugs in my code, this page takes everything from the db with a certain catID and lists them. It has page numbering for results over 5.
what it is doing with the page numbering is this. If theirare exectly 5 returns from db, then it will display a link for page 2, but their is no data for page 2.
Also if no results are returned from db it is supposed to say No results , but its not, It just displays nothing
<?
Connection stuff
$db = @mysql_select_db($db_name, $connection) or die("Error2 - ".mysql_error());
if(!$page_num || $page_num == "")
{
$page_num = 1;
}
$min = ($page_num - 1) 5;
$max = ($page_num 5) - 1;
$addquery = " LIMIT $min, 5";
$current_page = $page_num;
$sql3 = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ";
$result3 = @($sql3, $connection)
or die("Error3 - ".mysql_error());
if (!$result3 || $result3 == 0 || $result3 < 1) {
$contact_list = "<tr><td>No results</td></tr>";
} else {
$total_items = @mysql_num_rows($result3);
$sql = "SELECT * FROM $table_name WHERE catID = '$_REQUEST[id]' AND active = '1' ORDER BY busName $addquery";
$limit_result = @($sql, $connection) or die("Error 2 - PLEASE TRY LATER".mysql_error());
$page_num = ($total_items / 5) + 1;
// if $page_num = 0 then page_num = 1
while($row = mysql_fetch_array($limit_result)) {
$busID = $row['busID'];
$catID = $row['catID'];
$busName = $row['busName'];
$busEmail = $row['busEmail'];
$busLogo = $row['busLogo'];
$busPhone = $row['busPhone'];
$busUrl = $row['busUrl'];
$contact_list .= "<tr><td width='150' align='center' rowspan='2'>";
if($busLogo != "") { $contact_list .= "<img src='logo/$busLogo'>";}
$contact_list .= "</td>";
$contact_list .= "<td colspan='2' valign='top'><b>$busName</b></td></tr><tr>";
$contact_list .= "<td valign='top'><b>Email: </b><a href='mailto:$busEmail' class='buttons'>$busEmail</a><br><b>Tel: </b> $busPhone<br></td><td valign='top'>";
if($busUrl != "") { $contact_list .= "<b>Website : </b><a href='http://www.$busUrl' class='buttons' target='blank'>$busUrl</a> <br>";}
$contact_list .= "<a href='businessDetails.php?id=$busID' class='buttons'>More Details.....</a></td></tr>";
$contact_list .= "<tr><td colspan='3'><hr width='75%' color='#cccccc'></td></tr>";
} // end while
}
?>
<? include ("headerTop.php"); ?>
<? include ("buttons.php"); ?>
<table width="100%" height="381" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="150" valign="top">
<? include ("sideButtons.php"); ?>
</td>
<td height="381" align="center" valign="top"> <div align="center"><img src="images/viewBusiness.gif" width="400" height="37">
</div>
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr><td colspan="3" align="right"><?
If($page_num >= 2){
echo "Page :";
for($i=1;$i<=$page_num;$i++)
{
if($i != $current_page)
echo "<a href=\"showCategory.php?id=$_REQUEST[id]&page_num=$i\">$i</a> ";
else
echo "";
}
} else {
echo "";
}
?>
</td></tr>
<? echo "$contact_list" ?>
</table>
</td>
<td width="150" height="381" valign="top">
<? include ("advertisments.php"); ?></td>
</tr>
</table>
<table width="100%" height="70" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><? include ("footer.php"); ?></td>
</tr>
</table>
</body>
</html>