Hi guys,
Ok, so I'm using the code below to display the fields from a table on my webpage. I used some code to paginate the results as there's a lot of records, however I can't seem to get it working properly, and I'm going crazy trying to work out why.
As far as i can tell, I've defined everything properly, I've highlighted the line that's causing me issues in bold. It's where I call the results up, the last part "$website" should call up the result from the URL field in the db as a clickable url.
Can anyone help and show me where I'm going wrong please?
Thanks :)
<?php
$conn = mysql_connect(HOST,USER,PASS);
$db = mysql_select_db("db303278079") or die( "Unable to select database");
$sql = "SELECT COUNT(*) FROM ".RESTAURANTS." where area='manchester'";
$result = mysql_query($sql, $conn) or die ("unable to select db");
$r = mysql_fetch_row($result);
$numrows = $r[0];
$rowsperpage = 10;
$totalpages = ceil($numrows / $rowsperpage);
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
$currentpage = (int) $_GET['currentpage'];
} else {
$currentpage = 1;
}
if ($currentpage > $totalpages) {
$currentpage = $totalpages;
}
if ($currentpage < 1) {
$currentpage = 1;
}
$offset = ($currentpage - 1) * $rowsperpage;
$sql = "select * from ".IWARE_DOCS2." WHERE area='manchester' order by link_text LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or die ("unable to select db2");
$rest_name=mysql_result($result,$i,"link_text");
$address=mysql_result($result,$i,"address");
$telephone=mysql_result($result,$i,"telephone");
$website=mysql_result($result,$i,"url");
$cuisine_type=mysql_result($result,$i,"cuisine_type");
$website=(empty($website))?'':", <strong><A HREF=$website>Website</a></strong>";
while ($list = mysql_fetch_assoc($result)) {
[B]echo "<strong>" . $list['link_text'] . "</strong>" . " | " . $list['address'] . " | " . $list['telephone'] . $list['$website'] . "<br /><br>";[/B]
}
$range = 5;
if ($currentpage > 1) {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
$prevpage = $currentpage - 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
if (($x > 0) && ($x <= $totalpages)) {
if ($x == $currentpage) {
echo " [<b>$x</b>] ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
}
}
}
if ($currentpage != $totalpages) {
$nextpage = $currentpage + 1;
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
}
?>