next link continues even though no more data
Posted: Sun Aug 29, 2004 6:01 pm
hey im learnin how ot page number but my next link coninues linking even though theres no more record anyone no why ?
<?php
@mysql_connect("localhost", "user", "pass") or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db("db") or die("ERROR--CAN'T CONNECT TO DB");
$limit = 2;
$query_count = "SELECT * FROM news";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM news order by id desc LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
echo("<table class='notable'>");
while($row = mysql_fetch_array($result)){
$date=$row["dt"];
$comments=$row["comments"];
$comments = str_replace(";)", "<img src='smilies/wink.gif'>", $comments);
$comments = str_replace(":)", "<img src='smilies/happy.gif'>", $comments);
$comments = str_replace(":(", "<img src='smilies/sad.gif'>", $comments);
$comments = str_replace(":O", "<img src='smilies/shocked.gif'>", $comments);
$comments = str_replace(":D", "<img src='smilies/grin.gif'>", $comments);
$comments = str_replace(":P", "<img src='smilies/tongue.gif'>", $comments);
$comments = str_replace(":@", "<img src='smilies/mad.gif'>", $comments);
$comments = str_replace("8-)", "<img src='smilies/confused.gif'>", $comments);
$comments = str_replace(":'(", "<img src='smilies/cry.gif'>", $comments);
$comments = str_replace(":S", "<img src='smilies/sick.gif'>", $comments);
print("
<ul class='dots'>
<li>
$comments
</li>
</ul>
<p class='para' style='margin-left:450; margin-right:0;'>On : <font style='font-size:9'><b>$date</b></font>
<br><br><br><br><br>
");
}
echo("</table>");
if($page != 1){
$pageprev = $page-1;
echo("<a href=\"$PHP_SELF?page=$pageprev\"> [P] </a> ");
}else{
echo("[P] ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page+1;
echo("<a href=\"$PHP_SELF?page=$pagenext\"> >> </a>");
}else{
echo("[N]");
}
mysql_free_result($result);
?>
<?php
@mysql_connect("localhost", "user", "pass") or die("ERROR--CAN'T CONNECT TO SERVER");
@mysql_select_db("db") or die("ERROR--CAN'T CONNECT TO DB");
$limit = 2;
$query_count = "SELECT * FROM news";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM news order by id desc LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
echo("<table class='notable'>");
while($row = mysql_fetch_array($result)){
$date=$row["dt"];
$comments=$row["comments"];
$comments = str_replace(";)", "<img src='smilies/wink.gif'>", $comments);
$comments = str_replace(":)", "<img src='smilies/happy.gif'>", $comments);
$comments = str_replace(":(", "<img src='smilies/sad.gif'>", $comments);
$comments = str_replace(":O", "<img src='smilies/shocked.gif'>", $comments);
$comments = str_replace(":D", "<img src='smilies/grin.gif'>", $comments);
$comments = str_replace(":P", "<img src='smilies/tongue.gif'>", $comments);
$comments = str_replace(":@", "<img src='smilies/mad.gif'>", $comments);
$comments = str_replace("8-)", "<img src='smilies/confused.gif'>", $comments);
$comments = str_replace(":'(", "<img src='smilies/cry.gif'>", $comments);
$comments = str_replace(":S", "<img src='smilies/sick.gif'>", $comments);
print("
<ul class='dots'>
<li>
$comments
</li>
</ul>
<p class='para' style='margin-left:450; margin-right:0;'>On : <font style='font-size:9'><b>$date</b></font>
<br><br><br><br><br>
");
}
echo("</table>");
if($page != 1){
$pageprev = $page-1;
echo("<a href=\"$PHP_SELF?page=$pageprev\"> [P] </a> ");
}else{
echo("[P] ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page+1;
echo("<a href=\"$PHP_SELF?page=$pagenext\"> >> </a>");
}else{
echo("[N]");
}
mysql_free_result($result);
?>