Jump to content

page numbering


mforan

Recommended Posts

im building a forum and i was wondering how to make page numbers work, so only 10 or 20 posts show up, then it shows page 2, etc. like. 1, 2, 3, 4, 5

 

even better would be something like phpbb: 1 ... 6, 7, 8

 

 

im assuming this is some pretty advanced coding involved....

 

 

<?php
$query = "SELECT * FROM forum_posts WHERE topic_no='".$_REQUEST['topic_no']."' ORDER BY date ASC";
$result = mysql_query($query) or die("Error: ".mysql_error());
$fnames = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $fnames[] = $row; }
for ($i = 0; $i < count($fnames); $i++) {    

$query = "SELECT views FROM forum_posts WHERE topic_no='".$fnames[$i][8]."' AND author='1'";
$result = mysql_query($query) or die("Error: ".mysql_error());
$views = array();
$views = mysql_fetch_array($result, MYSQL_NUM);

$query = "SELECT createdate,alliance,rank,country,username FROM users WHERE username='".$fnames[$i][1]."'";
$result = mysql_query($query) or die("Error: ".mysql_error());
$user = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$data = $row;}

$query = "SELECT logo FROM udata WHERE username='".$fnames[$i][1]."'";
$result = mysql_query($query) or die("Error: ".mysql_error());
$logo = array();
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$logo = $row;}

$query = "SELECT COUNT(username) FROM forum_posts WHERE username='$data[4]'";
$result = mysql_query($query) or die("Error: ".mysql_error());
$postc = mysql_fetch_array($result, MYSQL_NUM);


$logoi = '<img src="'.$logo[0].'" width="100" height="100" /><br><br>';



$query = "SELECT admin FROM users WHERE username='".$fnames[$i][1]."'";
$result = mysql_query($query) or die("Error: ".mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$acount = $row;}
if ($acount[0] == 1) {
$mod[$i] = '<font color="lightgreen">ADMINISTRATOR</font><br>';
} else {
$query = "SELECT mteam FROM users WHERE username='".$fnames[$i][1]."'";
$result = mysql_query($query) or die("Error: ".mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {$mcount = $row;}
if ($mcount[0] == 1) {
$mod[$i] = '<font color="lightgreen">MODERATOR</font><br>';
}
}

if ($fnames[$i][1] == $info[3]) {

$buttons[$i] = '
<div class="forumbuttons">
<form action="forums_edit.php" method="post" class="lineup">
<input type="hidden" name="postid" value="'.$fnames[$i][0].'">
<input type="submit" name="edit" class="submit" value="Edit" />
</form>
<form action="forums_topic.php" method="post" class="lineup">
<input type="submit" name="delete" class="submit" value="Delete" />
<input type="hidden" name="postid" value="'.$fnames[$i][0].'">
<input type="hidden" name="username" value="'.$fnames[$i][1].'">
<input type="hidden" name="topicname" value="'.$fnames[$i][2].'">
<input type="hidden" name="forumid" value="'.$fnames[$i][6].'">
<input type="hidden" name="topic_no" value="'.$fnames[$i][8].'">
<input type="hidden" name="author" value="'.$fnames[$i][5].'">
</form>
</div>
';
} else {
$buttons[$i] = ' ';
}


echo '
<tr>
<td class="variable" align="center" valign="top"><a class="variable" href="browse.php?name='.$fnames[$i][1].'">'.$fnames[$i][1].'</a></td>
<td class="variable" align="left">Post Subject: <a class="noline">'.$fnames[$i][2].'</a></td>
</tr>
<tr>
<td align="left" valign="top" class="variable">
<div style="margin-left:10px">
'.$mod[$i].' 
'.$logoi.'
Joined: <a class="noline">'.date('d-m-Y', $data[0]).'</a><br>
Posts: <a class="noline">'.$postc[0].'</a><br>
Alliance: <a class="noline">'.$data[1].'</a><br>
Rank: <a class="noline">'.$data[2].'</a><br>
From: <a class="noline">'.$data[3].'</a><br>
</div></td>
<td align="left" valign="top" class="variable"><a class="noline">'.$fnames[$i][4].'</a>
</td>
</tr>

<tr>
  <td align="left" valign="center" class="variable"><div style="margin-left:10px"><a href="#top">Top</a></div></td>
  <td class="variable" align="right" valign="top"><div class="forumbuttons">'.$buttons[$i].'</div></td>
</tr>
';
}
?>     
        </table>
        <br>
        <form action="forums_topic.php" method="post">
        <table width="540" class="metal" cellpadding="1" cellspacing="1">
          <tr>
            <td colspan="2" class="head">Reply</td>
          </tr>
          <tr>
            <td width="108" height="19" valign="top" class="variable"><div align="left">Message body:<br>
            <a class="noline">Enter your message here, it may contain no more than <STRONG>60000</STRONG> characters.</a></div></td>
            <td width="381" class="variable"><textarea name="message" id="message" cols="60" rows="8"></textarea></td>
          </tr>
          <tr>
            <td height="19" colspan="2" valign="top" class="variable"><div align="center">
              
              <input type="hidden" value="<?php echo $forumid;?>" name="forumid">
              <input type="hidden" value="<?php echo $_REQUEST['topic_no'];?>" name="topic_no">
              <input type="hidden" value="<?php echo $tname;?>" name="topicname">
              <input name="posted_reply" type="submit" class="submit" id="button" value="Submit">
            </div></td></tr>
        </table>
        </form>
        <?php } ?>

 

the code above is the output for the posts. help would muchly be appreciated!

Link to comment
Share on other sites

A simple solution is to do something like this:

$displayLimit = 10;
$startFrom = $_GET['page'] * $displayLimit;
$query = mysql_query("SELECT * FROM `posts` LIMIT $startFrom, $displayLimit");

 

The numbering shouldn't give you any problems. Just have a next button that increments the current page ID value.

 

Example:

1) mypage.php?page=2

2) $_GET['page'] has the current page number. $_GET['page'] +/-1 for going back/forwards.

3) Query sent: "SELECT * FROM `posts` LIMIT 20, 10" - selects 10 posts starting from record 20.

 

Obviously this is a basic example and you'd need to expand upon it but it should give you a good starting point.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.