next link continues even though no more data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
User avatar
buddok
Forum Commoner
Posts: 50
Joined: Tue May 25, 2004 2:44 pm

next link continues even though no more data

Post by buddok »

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>&nbsp;");
}else{
echo("[P] &nbsp;");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i."&nbsp;");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;");
}
}


if(($totalrows % $limit) != 0){
if($i == $page){
echo($i."&nbsp;");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a>&nbsp;");
}
}

if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page+1;

echo("<a href=\"$PHP_SELF?page=$pagenext\"> >> </a>");
}else{
echo("[N]");
}

mysql_free_result($result);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no need to start a new thread. :roll:

original thread: viewtopic.php?t=25544
Locked