Jump to content

forum pagination trouble?


simmsy

Recommended Posts

Hi im having trouble getting the topic replies to form in pagination results? please help.

Heres the code:

 

  <?php

  $url=curPageURL();

  //Connect to DB

include("connect.php");

// get value of id that sent from address bar

$web_id=$_GET['id'];

 

  $searchresult=mysql_query("SELECT id, username, title, detail FROM forum_topic WHERE id='$web_id'") or die(mysql_error());

 

while($row=mysql_fetch_array($searchresult)) {

  //the format is $variable = $r["nameofmysqlcolumn"];

  //modify these to match your mysql table columns

 

  $id = $row['id'];

                                $username = $row['username'];

                                $title = $row['title'];

$detail = $row['detail'];

 

 

 

                              echo "

             

                <tr><td width='20'># $id</td><td width='100' align='center' valign='middle'><a href='forum-viewtopic.php?id=$id'><b>$username: </b></a></td>

                <td valign='middle'><em>$title</em></td></tr>

<tr><td colspan='3'>$detail</td></tr>

<tr><td colspan='3'><hr size='1'></td></tr>";

}

 

?>

<p />

<?php

$limit = 2; //Number of results per page 

$page=$_GET["page"]; //Get the page number to show

if($page == "") $page=1; //If no page number is set, the default page is 1

 

//Get the number of results

$searchresult=mysql_query("SELECT * FROM search ORDER BY id") or die(mysql_error());

$numberofresults=mysql_num_rows($searchresult);

 

//Get the number of pages

$numberofpages=ceil($numberofresults/$limit);

  $searchresult=mysql_query("SELECT id, username, reply FROM forum_reply ORDER BY id LIMIT " . ($page-1)*$limit . ",$limit") or die(mysql_error());

 

while($row=mysql_fetch_array($searchresult)) {

  //the format is $variable = $r["nameofmysqlcolumn"];

  //modify these to match your mysql table columns

 

  $id = $row['id'];

                                $username = $row['username'];

                                $reply = $row['reply'];

 

 

 

                              echo "

             

                <tr><td width='100' align='center' valign='middle'><b>$username: </b></td>

<tr><td colspan='2'>$reply</td></tr>

<tr><td colspan='2'><hr size='1'></td></tr>";

}

 

$nav="";

if($page > 1) {

$nav .= "<a href=\"viewtopic.php?page=" . ($page-1) . "&searchstring=" .urlencode($searchstring) . "\"><< Prev</A>";

}

for($i = 1 ; $i <= $numberofpages ; $i++) {

if($i == $page) {

$nav .= "<b>$i</b>";

}else{

$nav .= "<a href=\"viewtopic.php?page=" . $i . "&searchstring=" .urlencode($searchstring) . "\"> $i </A>";

}

}

if($page < $numberofpages) {

$nav .= "<a href=\"viewtopic.php?page=" . ($page+1) . "&searchstring=" .urlencode($searchstring) . "\">Next >></A>";

}

 

Echo "<br><br>" . $nav;

?>

 

It does work but I want the replies just to appear for the correlating topic?, the next and previous page links appear above the replies?? and I want the topic to stay on every next or previous page?

Can anyone help? just this to do then can finally get the site up and running?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/199657-forum-pagination-trouble/
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.