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
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 7:54 am
hey well im using this bit of code in my pagination and it conintues to link to the next page even though theres no more data ?
Code: Select all
<?php
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"> [N] </a>");
}else{
echo("[N]");
}
?>
anyone got n e ideas why becuase i realy cant see it ?
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Aug 29, 2004 8:49 am
Add some debugging code:
Code: Select all
echo 'Totalrows: '.$totalrows.'<br />';
echo 'Limit: '.$limit.'<br />';
echo 'Page: '.$page.'<br />';
echo 'Calc: '.($totalrows - ($limit * $page)).'<br />';
if(($totalrows - ($limit * $page)) >= 0){
//rest of your code here..
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 9:25 am
wat does that do :S ?
malcolmboston
DevNet Resident
Posts: 1826 Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK
Post
by malcolmboston » Sun Aug 29, 2004 9:27 am
it will print out all the variables on each page so you can check where / if your formula is going wrong
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Aug 29, 2004 9:41 am
If you're seeing the next page link then if(($totalrows - ($limit * $page)) >= 0){ must be true, which means one of the values in that calculation isn't what you think it is, so by echoing them out you can see where it's going wrong.
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 10:39 am
ok im a newbie realy sowwi but i dont get that
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Sun Aug 29, 2004 12:58 pm
did you try inserting that debugging code?
Show us the results.
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 1:08 pm
yer it cam up with an error
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Aug 29, 2004 1:37 pm
buddok wrote: yer it cam up with an error
well, hmm...
lets think.....
- thinking.....
......thinking -
wouldnt you think it would be useful for us to know that error?
Help us help you
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 1:41 pm
why do u have to be a smurfy smurf about it tim ?
feyd | smurfilized
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Sun Aug 29, 2004 1:43 pm
well phen asked:
"Show us the results"
We are trying to be nice by helping you, and you must have been caught in a "duh" moment b/c posting "yeah I got an error, but I am not going to tell you it."
Can you please post the error you got?
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 1:56 pm
no because after i tried it an it didnt work i got rid of it is there no obvious incorrections in my script ? how is it usualy done ?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Aug 29, 2004 2:15 pm
your code is highly dependant on variables.. we need to know what those variables are, in detail, before we can make an accurate assessment. if the code mark was kind enough to spend the time to write out for you was added in the proper place.. it should work without any problems. (that code, not necessarily yours)
buddok
Forum Commoner
Posts: 50 Joined: Tue May 25, 2004 2:44 pm
Post
by buddok » Sun Aug 29, 2004 2:47 pm
Code: Select all
<?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);
?>
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Aug 29, 2004 8:48 pm
Ok, i'll try again.
If you're seeing the next page link when you shouldn't be doing then it means if(($totalrows - ($limit * $page)) >= 0){ is true when you expect it not to be.
So that means the variables probably are not what you think they are, you can find out what they are by echo'ing them out, such as:
Code: Select all
echo 'Totalrows: '.$totalrows.'<br />';
echo 'Limit: '.$limit.'<br />';
echo 'Page: '.$page.'<br />';
echo 'Calc: '.($totalrows - ($limit * $page)).'<br />';
if(($totalrows - ($limit * $page)) >= 0){
//rest of your code here..
By doing this you will see what the values of the variables are and why the calculation is returning true instead of false.