Jump to content

Pagination help again


liam1412

Recommended Posts

Hi

I have tried a different method of pagination.  I am nw getting a parse error that points toward the last line of the code. i assume it's a semi-colon or curly bracket missing but can't find it.  Can anyone help,

Thanks

[code]<?php
$limit = 20;
$query_count = "SELECT count(*)FROM forum_question WHERE forum_id = $forum_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_question WHERE forum_id = $forum_id LIMIT $limitvalue, $limit";
$topic_result = mysql_query($topic_query)or die("Error: " . mysql_error());


while($topic_rows = mysql_fetch_array($topic_result)){ //loop table row while topic exists
?>

<tr bgcolor="#6d6d6d">
<td width="60" align="center">
<?php
if($topic_rows['topic_status'] == 1){
echo '<img src = "images/norm_post_locked.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 2){
echo '<img src = "images/norm_post_sticky.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 3){
echo '<img src = "images/norm_post_locked_sticky.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 4){
echo '<img src = "images/hot_post.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 5){
echo '<img src = "images/hot_post_locked.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 6){
echo '<img src = "images/hot_post_sticky.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 7){
echo '<img src = "images/hot_post_locked_sticky.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 0){
echo '<img src = "images/norm_post.jpg" width="35" height="41" alt="Hot Topic" />';}
?>
<td width="240">
<table width="240" cellspacing="0" cellpadding="0" border="0">
<tr>
    <td><a href="view_topic.php?topic_id=<?php echo $topic_rows['topic_id'];?>"><?php echo $topic_rows['topic'];?></a></td>
</tr>
<tr>
    <td align="right">

<?php
if($_SESSION['user_level'] != 0){
?>
<br />
<a href='lock_thread.php?topic_id=".$topic_rows['topic_id']."'><img src='images/lock_thread.jpg' width="25" height="25" border="0" alt='Lock Thread' /></a>&nbsp;&nbsp
<a href="make_sticky.php?topic_id=".$topic_rows['topic_id'].""><img src="images/make_sticky.jpg" width="25" height="25" border="0" alt="Make Sticky" /></a>&nbsp;&nbsp
    <a href="delete_thread.php?topic_id=<?php echo $topic_rows['topic_id']; ?>"><img src="images/delete.jpg" width="25" height="25" border="0" alt="Delete Thread" /></a>&nbsp;&nbsp;
<?php
};
?>
</td>
</tr>
</table>
</td>
    <td width="100" align="center"><p class="grey"><?php echo $topic_rows['topic_starter_name'];?></p></td>
    <td width="45" align="center"><p class="grey"><?php echo $topic_rows['topic_view'];?></p></td>
    <td width="45" align="center"><p class="grey"><?php echo $topic_rows['topic_reply'];?></p></td>
    <td width="110" align="left"><p class="lastpost"><b>Made By:&nbsp;&nbsp;</b><?php echo $topic_rows['last_post_by'];?><br /><b>On:&nbsp;</b><?php echo $topic_rows['last_post_date_time'];?></b></p></td>
</tr>
<?php
if($page != 1){
$pageprev = $page--;
echo("<a href=\"$PHPSELF&page=$pageprev\">PREV" .$limit. "</a> ");
}else{

echo ("PREV" .$limit. " ");

$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++;
  echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
}else{
      echo("NEXT".$limit); 
 

}   
mysql_close();
?>
</table>

<?php include 'footer.php';?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34700-pagination-help-again/
Share on other sites

I have managed to resolve the first issue but now the Prev and Next links are not links and it isn't adding the page numbers in between the prev and next.

I have my limit set at 20

When my forum as more than 20 topics the prev Next Link looks like this

PREV 1 NEXT -- But none of them ar actually links

Please help
Link to comment
https://forums.phpfreaks.com/topic/34700-pagination-help-again/#findComment-163543
Share on other sites

I think it's acting as if there isn't any more records there but there is definatley.

Here is my ammended code I have up to now.

[code]<?php
$limit = 20;
$query_count = "SELECT count(*)FROM forum_question WHERE topic_forum_id = $forum_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_question WHERE topic_forum_id = $forum_id LIMIT $limitvalue, $limit";
$topic_result = mysql_query($topic_query)or die("Error: " . mysql_error());


while($topic_rows = mysql_fetch_array($topic_result)){ //loop table row while topic exists
?>

<tr bgcolor="#6d6d6d">
<td width="60" align="center">
<?php
if($topic_rows['topic_status'] == 1){
echo '<img src = "images/norm_post_locked.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 2){
echo '<img src = "images/norm_post_sticky.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 3){
echo '<img src = "images/norm_post_locked_sticky.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 4){
echo '<img src = "images/hot_post.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 5){
echo '<img src = "images/hot_post_locked.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 6){
echo '<img src = "images/hot_post_sticky.jpg" width="35" height="41" alt="Norm Topic" />';}
elseif($topic_rows['topic_status'] == 7){
echo '<img src = "images/hot_post_locked_sticky.jpg" width="35" height="41" alt="Hot Topic" />';}
elseif($topic_rows['topic_status'] == 0){
echo '<img src = "images/norm_post.jpg" width="35" height="41" alt="Hot Topic" />';}
?>
<td width="240">
<table width="240" cellspacing="0" cellpadding="0" border="0">
<tr>
    <td><a href="view_topic.php?topic_id=<?php echo $topic_rows['topic_id'];?>"><?php echo $topic_rows['topic'];?></a></td>
</tr>
<tr>
    <td align="right">

<?php
if($_SESSION['user_level'] != 0){
?>
<br />
<a href='lock_thread.php?topic_id=".$topic_rows['topic_id']."'><img src='images/lock_thread.jpg' width="25" height="25" border="0" alt='Lock Thread' /></a>&nbsp;&nbsp
<a href="make_sticky.php?topic_id=".$topic_rows['topic_id'].""><img src="images/make_sticky.jpg" width="25" height="25" border="0" alt="Make Sticky" /></a>&nbsp;&nbsp
    <a href="delete_thread.php?topic_id=<?php echo $topic_rows['topic_id']; ?>"><img src="images/delete.jpg" width="25" height="25" border="0" alt="Delete Thread" /></a>&nbsp;&nbsp;
<?php
};
?>
</td>
</tr>
</table>
</td>
    <td width="100" align="center"><p class="grey"><?php echo $topic_rows['topic_starter_name'];?></p></td>
    <td width="45" align="center"><p class="grey"><?php echo $topic_rows['topic_view'];?></p></td>
    <td width="45" align="center"><p class="grey"><?php echo $topic_rows['topic_reply'];?></p></td>
    <td width="110" align="left"><p class="lastpost"><b>Made By:&nbsp;&nbsp;</b><?php echo $topic_rows['last_post_by'];?><br /><b>On:&nbsp;</b><?php echo $topic_rows['last_post_date_time'];?></b></p></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"); 
 

 
mysql_close();
?>
</table>

<?php include 'footer.php';?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/34700-pagination-help-again/#findComment-163544
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.