liam1412
18-01-2007, 23:52
Hello Techy Peeps
I have ripped this pagination code word for word from a php tutorial site and its not working. Had a post on that site for ages now and no one seems to want to help so wondering if anyone on here had any clue.
Basically what is happening is this.
My limit is set at 10 and on the particular page I am testing it on I know there are 13 records in my result set
The pagination looks like this
PREV 1 NEXT
But it should read
PREV 1 2 NEXT as there should be a second page.
Also NONE OF THEM ARE LINKS
its as if it is ignoring the rest of the result set after the limit
<?php
$limit = 10;
$query_count = "SELECT count(*)FROM forum_answer WHERE ans_topic_id = $topic_id";
$result_count = mysql_query($query_count);
$total_rows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$topic_query = "SELECT * FROM forum_answer WHERE ans_topic_id = $topic_id ORDER BY ans_id LIMIT $limitvalue, $limit";
$topic_result = mysql_query($topic_query)or die("Error: " . mysql_error());
while
($fetch_replies = mysql_fetch_array($topic_result)){
$ans_text = $fetch_replies['ans_text'];
$ans_id = $fetch_replies['ans_id'];
$ans_topic_id = $fetch_replies['ans_topic_id'];
$ans_text = nl2br($ans_text);
$ans_text = BBCODE($ans_text);
?>
<tr>
<td valign="center" width="150" bgcolor="#565656"><p class="grey">
<?php echo $fetch_replies['ans_datetime'];?>
<br />
<br />
<?php echo $fetch_replies['ans_poster_username'];?>
<br />
<img src="images/profilepics/vw.jpg" width="50" height="50" border="2" />
</p></td>
<td valign="top" width="450" bgcolor="#6d6d6d">
<table width="450" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="2"><p class="grey"><?php echo $ans_text; ?></p></td>
</tr>
<tr>
<td width="350" align="right"></td>
<td width="100" align="right">
<br />
<br />
<br />
<br />
<?php if($fetch_replies['ans_poster_username'] == $_SESSION['username']){
?>
<a href="edit_reply.php?ans_id=<?php echo $ans_id ?>&ans_topic_id=<?php echo $ans_topic_id; ?>"><img src="images/edit_post.jpg" width="25" height="25" border="0" alt="Edit Reply" /></a>
<?php
};
?>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
if($page != 1){
$pageprev = $page--;
echo("<a href=\"$PHPSELF&page=$pageprev\">PREV</a> ");
}else{
echo ("PREV");
$numofpages = $total_rows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else
echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
}
}
if(($total_rows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
}
}
if(($total_rows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT</a>");
}else{
echo("NEXT");
}
if($no_of_views == 199){
$sql_hot_topic = "UPDATE forum_question SET topic_status = $topic_update WHERE topic_id = '$topic_id'";
mysql_query($sql_hot_topic)or die("unable to update topic status");
}
$sql_update_topic_view = "UPDATE forum_question SET topic_view = '$topic_view' WHERE topic_id = '$topic_id'";
mysql_query($sql_update_topic_view)or die("failed to update topic_reply");
mysql_close();
?>
Been looking at it for three days now and can't spot anything different to the tutorial apart from I echo my php as and when rather than echoing all the styling etc.
I have ripped this pagination code word for word from a php tutorial site and its not working. Had a post on that site for ages now and no one seems to want to help so wondering if anyone on here had any clue.
Basically what is happening is this.
My limit is set at 10 and on the particular page I am testing it on I know there are 13 records in my result set
The pagination looks like this
PREV 1 NEXT
But it should read
PREV 1 2 NEXT as there should be a second page.
Also NONE OF THEM ARE LINKS
its as if it is ignoring the rest of the result set after the limit
<?php
$limit = 10;
$query_count = "SELECT count(*)FROM forum_answer WHERE ans_topic_id = $topic_id";
$result_count = mysql_query($query_count);
$total_rows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$topic_query = "SELECT * FROM forum_answer WHERE ans_topic_id = $topic_id ORDER BY ans_id LIMIT $limitvalue, $limit";
$topic_result = mysql_query($topic_query)or die("Error: " . mysql_error());
while
($fetch_replies = mysql_fetch_array($topic_result)){
$ans_text = $fetch_replies['ans_text'];
$ans_id = $fetch_replies['ans_id'];
$ans_topic_id = $fetch_replies['ans_topic_id'];
$ans_text = nl2br($ans_text);
$ans_text = BBCODE($ans_text);
?>
<tr>
<td valign="center" width="150" bgcolor="#565656"><p class="grey">
<?php echo $fetch_replies['ans_datetime'];?>
<br />
<br />
<?php echo $fetch_replies['ans_poster_username'];?>
<br />
<img src="images/profilepics/vw.jpg" width="50" height="50" border="2" />
</p></td>
<td valign="top" width="450" bgcolor="#6d6d6d">
<table width="450" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="2"><p class="grey"><?php echo $ans_text; ?></p></td>
</tr>
<tr>
<td width="350" align="right"></td>
<td width="100" align="right">
<br />
<br />
<br />
<br />
<?php if($fetch_replies['ans_poster_username'] == $_SESSION['username']){
?>
<a href="edit_reply.php?ans_id=<?php echo $ans_id ?>&ans_topic_id=<?php echo $ans_topic_id; ?>"><img src="images/edit_post.jpg" width="25" height="25" border="0" alt="Edit Reply" /></a>
<?php
};
?>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
if($page != 1){
$pageprev = $page--;
echo("<a href=\"$PHPSELF&page=$pageprev\">PREV</a> ");
}else{
echo ("PREV");
$numofpages = $total_rows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else
echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
}
}
if(($total_rows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
}
}
if(($total_rows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT</a>");
}else{
echo("NEXT");
}
if($no_of_views == 199){
$sql_hot_topic = "UPDATE forum_question SET topic_status = $topic_update WHERE topic_id = '$topic_id'";
mysql_query($sql_hot_topic)or die("unable to update topic status");
}
$sql_update_topic_view = "UPDATE forum_question SET topic_view = '$topic_view' WHERE topic_id = '$topic_id'";
mysql_query($sql_update_topic_view)or die("failed to update topic_reply");
mysql_close();
?>
Been looking at it for three days now and can't spot anything different to the tutorial apart from I echo my php as and when rather than echoing all the styling etc.