Jump to content

Numbering posts dependign on page number


runnerjp

Recommended Posts

Im tryign to number the posts on my forum. These numbers only refer to posts under a topic. Im not counting how many posts are under a topic but just giving them a number.

At the moment i have this script in place:

 

$counter2 = 1;
$counter2++;

 

The problem is when a go to page 2 it starts from 2 again.

 

here is the full forum code so you can get an idea how it works

 

<?php
require_once '../settings.php';

checkLogin('1 2');
include "../info.php";    // sets username/id ect
include "../getuser.php"; // records user view on page
include "checkinfo.php";  //Your ip address is...;
include "../BBClass.php"; //class for bbcode
$gettopic3=mysql_fetch_assoc(mysql_query("SELECT * from forumtutorial_posts where postid='$forumpostid'"));
include "forumnav.php";   // shows where you are on the forum
$getuser = mysql_fetch_assoc(mysql_query("SELECT * from users where Username='$username'"));

if ($notify == "yes")
    {
    $updateemail="DELETE FROM forum_email  WHERE topic_id='$forumpostid' AND user_id = '$id'";
    mysql_query($updateemail) or die(mysql_error());
    }

//Here we count the number of results
//Edit $data to be your query
$data     =mysql_query("SELECT * from forumtutorial_posts where parentid='$forumpostid'") or die(mysql_error());
$rows     =mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows= 5;

//This sets the range to display in our query
if ($pagenum === "last")
    {
    $query ="Select COUNT(*) as C from forumtutorial_posts where parentid='$forumpostid'";
    $result=mysql_query($query);
    $data  =mysql_fetch_array($result);

    if ($data['C'] == 0)
        $pagenum=1;
    else
        $pagenum=ceil($data['C'] / $page_rows);
    }

$pagenum                    =(is_numeric($pagenum) && $pagenum >= 1) ? (int)$pagenum : 1;
$max                        ='limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows;
//This is your query again, the same one... the only difference is we add $max into it
$start = (($pagenum-1) * $page_rows)+1;

{
    }
?>

<table width = "80%" align="center">
    <tr>
        <td width = "36%" height = "21">
            <?php
            $getusersonline ="SELECT user_id,user FROM useronline 
   WHERE 
(file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid' or
  file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&forum=general' or
  file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid' or
  file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=$pagenum' or
    file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&notify=yes' or
  file LIKE 'http://www.runningprofiles.com/members/index.php?page=message&forum=$forum&id=$forumpostid&pagenum=last' )
  

   
   AND
  timestamp > "
                . (time() - 900); //grab from sql users on in last 15 minutes
            $getusersonline2=mysql_query($getusersonline) or die("Could not get users");
            $num            =mysql_num_rows($getusersonline2);

            echo " <b>Currently Viewing: </b>";

            $tmp=array();

            while ($getusersonline3=mysql_fetch_array($getusersonline2))
                {
                $tmp[]="<a href='$getusersonline3[user]'>$getusersonline3[user]</a>";
                }

            echo implode(',', $tmp);
            ?>
        </td>

        <td width = "64%" align = "right" valign = "bottom">
            <div align = "right"><a href = "index.php?page=mainforums">

                <img src = "/images/homeforum.gif" alt = "home" border = "0"/></a> <?php echo ' <a href="index.php?page=forum&forum=
$forum">' ?><img src = "/images/backforum.gif" border = "0" alt = "back"/>

                </a>

                <?php
                if ($gettopic3['forumlock'] == 0)
                    {
                ?>

                <?php
                    echo ' <a href="index.php?page=reply&id=$forumpostid&forum=$forum">'
                ?>

                                    <img src = "/images/post_reply.gif" border = "0" alt = "reply"/>

                                    </a>
            </div>

            <?
                    }
            ?></td>
    </tr>

    <?php
    if ($pagenum == 1)
        {
    ?>
</table>

<table width = "90%" align="center" cellpadding = "0" cellspacing = "0" >
            <tr>
                <td>
                    <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin">
                       <tr>
                    <td colspan="3" align="right" class = 'border'><table width="100%" style = "height:auto" >
                      <tr>
                        <td width="15%" align="left"><font size="2" color="white">  <a name="<?php echo $gettopic3['postid'] ?>" href = 'http://www.runningprofiles.com/members/index.php?page=message&forum=<?php echo $forum ?>&id=<?php echo $forumpostid ?>#<?php echo $gettopic3['postid'] ?>'><strong>#1</strong></a></font></td>
                        <td width="32%" align="left"></td>
                        <td width="33%" align="right"><font size="2" color="white">» Posted
                            <?
                                            $dbtime=$gettopic3['showtime'];
                                            $time  =date("F j Y, g:i a", $dbtime);

                                            $time  =date("F j, Y, g:i a", $dbtime);
                                            gettheTime($dbtime, $time);
                                        ?>
 «   </font></td>
                      </tr>
                    </table></td>
                    </tr>

                        <tr>
                            <td width = "20%" align = "center" valign = "middle" class = "forum_view_topic_header_2_b"
                            ><a href = '/members/<? echo
$getreplies3['author']; ?>'>

                                <span class = "style5"><? echo "<b>". $gettopic3['author']." </b>" ?></span></a> <?php
                                $result = mysql_query(
                                              "SELECT * FROM useronline WHERE(user='" . $gettopic3['author'] . "')");

                                while ($row=mysql_fetch_array($result))
                                    {
                                    $last_active=time() - $row['timestamp'];
                                    }

                                echo ($last_active < 300)
                                         ? '<img src="http://www.runningprofiles.com/images/useron.gif" width="12" height="11" alt= "usron" />'
                                         : '<img src="http://www.runningprofiles.com/images/useroff.gif" width="12" height="11"  alt= "usroff" />';
                            ?>
                                <br />
                              <?
                                $query="SELECT * FROM users WHERE Username = '" . $gettopic3['author'] . "' LIMIT 1";

                                if ($result=mysql_query($query))
                                    {
                                    if (mysql_num_rows($result))
                                        {
                                        $array  =mysql_fetch_assoc($result);
                                        $image  =$array['image'];
                                        $postnum=$array['post_count'];

                                        echo
                                            "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" alt =\"mini\"  />";
                            ?> 
                              <br />

                                    
                                        <span class = "style7"> Posts: <?php echo $postnum; ?> </span>

                            <?
                                        }
                                    }
                            ?>
                            </td>

                            <td width = "85%" colspan="2" style="background-color:white">
                                <table width = "100%" border = "0" cellpadding = "5" cellspacing = "0">
                                    <tr>
                                                                                <td width="96%" valign = "top"><span class="style1">
                                          <?php
                                                            $message =nl2br($gettopic3['post']);
                                                            $b =new BBCode();
                                                            $b->selection=nl2br($message);
                                                            $b->parseCode();
                                                            echo nl2br($b->parsed);
                                                        ?>
                                      </span></td>

                                    </tr>

                                    <tr>
                                        <td align = "left" valign = "top"></td>
                                    </tr>

                                    <tr>
                                        <td height = "27" colspan = "2" align = "right" >
                                           </td>
                                    </tr>

                                    <tr>
                                        <td height = "28" align = "right" valign = "top">
                                          <a href = "index.php?page=reply&forum=<?php echo $forum; ?>&id=<? echo
$forumpostid ?>&pid=<? echo $gettopic3['postid']; ?>"><img src = "/images/quote.gif" border = "0" height="16" width="16" alt = "Quote"/></a>
                                          <?php
                                            $dbtime =$gettopic3['showtime'];
                                            $intTime=time();
                                            $intDiff=$intTime - $dbtime;

                                            if ($intDiff < 7200 && $gettopic3['author'] != $username)
                                                {
                                        ?>
<?php include "include/editmessage.php"; // shows where you are on the forum ?>
                                          <a href = "index.php?page=editmessage&forum=<?php echo $forum; ?>&id=<? echo
$forumpostid ?>&pid=<? echo $gettopic3['postid']; ?>"><img src = "/images/edit.bmp" border = "0" alt = "Edit"/></a>
                                          <?php
                                                }
                                        ?>
<?php


                                            //Now increase it:
                                            $CONT_ID++;

                                            ;
                                        ?>

                                      

                                      </td>

                                        <td width = "4%" align = "right" valign = "bottom"> </td>
                                    </tr>
                          </table></td>
                      </tr>
                    </table></td>
            </tr>
        </table>

    <?php
        }


    $getreplies
                =
        "Select * from forumtutorial_posts where parentid='$forumpostid' ORDER BY showtime $max"; //getting replies

    $getreplies2=mysql_query($getreplies) or die(mysql_error() . "Could not get replies");
$counter2 = 1;
    while ($getreplies3=mysql_fetch_array($getreplies2))
        {
    ?><br />

        <table width = "90%" align="center" cellpadding = "0" cellspacing = "0" >
            <tr>
                <td>
                    <table width = "100%" align = "center" cellpadding = "0" cellspacing = "0" class="loggedin">
                       <tr>
                    <td colspan="3" align="right" class = 'border'>  <table width="100%">
                      <tr>
                        <td width="15%" align="left"><font size="2" color="white">   

<?php
$counter2++;
?>

<a name="<?php echo $getreplies3['postid'] ?>"> </a><a href ='http://www.runningprofiles.com/members/index.php?page=message&forum=<?php echo $forum ?>&id=<?php echo $forumpostid ?>#<?php echo $getreplies3['postid'] ?>'><strong>#<?php echo $counter2;?></strong></a></font></td>
                        <td width="32%" align="left"> </td>
                        <td width="33%" align="right"><font size="2" color="white">» Replied
                            <?
                                            $dbtime=$getreplies3['showtime'];
                                            $time  =date("F j Y, g:i a", $dbtime);

                                            $time  =date("F j, Y, g:i a", $dbtime);
                                            gettheTime($dbtime, $time);
                                        ?>
 «   </font></td>
                      </tr>
                    </table></td>
                    </tr>

                        <tr>
                            <td class = "forum_view_topic_header_2_b" width = "20%" align = "center" valign = "middle"
                            ><a href = '/members/<? echo
$getreplies3['author']; ?>'>

                                <span class = "style5"><? echo "<b>". $getreplies3['author']." </b>" ?></span></a>
                              <?php
                                $result = mysql_query(
                                              "SELECT * FROM useronline WHERE(user='" . $getreplies3['author'] . "')");

                                while ($row=mysql_fetch_array($result))
                                    {
                                    $last_active=time() - $row['timestamp'];
                                    }

                                echo ($last_active < 300)
                                         ? '<img src="http://www.runningprofiles.com/images/useron.gif" width="12" height="11" alt= "usron" />'
                                         : '<img src="http://www.runningprofiles.com/images/useroff.gif" width="12" height="11"  alt= "usroff" />';
                            ?>
                              <br />
                              <?
                                $query="SELECT * FROM users WHERE Username = '" . $getreplies3['author'] . "' LIMIT 1";

                                if ($result=mysql_query($query))
                                    {
                                    if (mysql_num_rows($result))
                                        {
                                        $array  =mysql_fetch_assoc($result);
                                        $image  =$array['image'];
                                        $postnum=$array['post_count'];

                                        echo
                                            "<img src=\"http://www.runningprofiles.com/members/images/mini/$image\" border=\"1\" alt =\"mini\"  />";
                            ?>
                              <br />

                                    
                                        <span class = "style7"> Posts: <?php echo $postnum; ?> </span>

                            <?
                                        }
                                    }
                            ?>
                            </td>

                            <td width = "85%" colspan="2" style="background-color:white">
                              <table width = "100%" border = "0" cellpadding = "5" cellspacing = "0">
                                    <tr>
                                        
                                        <td width="96%" valign = "top">
                                          <?php     
                                                            $message =nl2br($getreplies3['post']);
                                                            $b =new BBCode();
                                                            $b->selection=nl2br($message);
                                                            $b->parseCode();
                                                            echo nl2br($b->parsed);
                                                        ?>
                                     </td>

                                    </tr>

                                    
                                    <tr>
                                        <td align = "left" valign = "top"></td>
                                    </tr>

                                    <tr>
                                        <td height = "27" colspan = "2" align = "right" >
                                         </td>
                                    </tr>

                                    <tr>
                                        <td height = "28" align = "right" valign = "top">
                                          <a href = "index.php?page=reply&forum=<?php echo $forum; ?>&id=<? echo
$forumpostid ?>&pid=<? echo $getreplies3['postid']; ?>"><img src = "/images/quote.gif" border = "0" height="16" width="16" alt = "Quote"/></a>
                                          <?php
                                            $dbtime =$getreplies3['showtime'];
                                            $intTime=time();
                                            $intDiff=$intTime - $dbtime;

                                            if ($intDiff < 7200 && $getreply3['author'] != $username || $getuser = 'Admin')
                                                {
                                      
                                               

                                                   include 'editmessage.php';   

                                            //Now increase it:
                                            $CONT_ID++;
                                              } 
                                            ;
                                        ?>

                                      

                                  </td>

                                        <td width = "4%" align = "right" valign = "bottom"> </td>
                                    </tr>
                                </table></td>
                        </tr>
                    </table></td>
            </tr>
        </table>



    <?
        }
    ?>

    <?
    echo "<br /><center>";

    // Find out the total number of pages depending on the limit set
    $numofpages=$rows / $page_rows;
    $totalpages=ceil($numofpages);
    // Start links for pages
    $maxpage   =$totalpages == 0 ? 1 : $totalpages;                   // add this line
    echo "Page " . $pagenum . " of " . $maxpage . "</center>"; // change this



   // Sets link for previous 25 and return to page 1
    
     if ($pagenum != 1)
        {
        $pageprev=($pagenum - 1);
        echo "<center><a href=\"" . $_SERVER['PHP_SELF']
                 . "?page=message&forum=$forum&id=$forumpostid&pagenum=1\"><<</a>  ";
        echo "<a href=\"" . $_SERVER['PHP_SELF']
                 . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pageprev\">PREV </a> ";
        }
    else
        {
        echo "<center>PREV ";
        }
   

    // Loop thru all the pages and echo out the links
    for ($i=1; $i <= $numofpages; $i++)
        {
        if ($i == $pagenum)
            {
            echo "[" . $i . "] ";
            }
        else
            {
            echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> ";
            }
        }

    // Check for straglers after the limit blocks
    if (($rows % $page_rows) != 0)
        {
        if ($i == $pagenum)
            {
            echo "[" . $i . "] ";
            }
        else
            {
            echo "<a href=\"" . $_SERVER['PHP_SELF'] . "?page=message&forum=$forum&id=$forumpostid&pagenum=$i\">$i</a> ";
            }
        }

     // Print out the Next 25 and Goto Last page links
if (($rows - ($page_rows * $pagenum)) > 0)
        {
        $pagenext=$pagenum++;
        echo "<a href=\"" . $_SERVER['PHP_SELF']
                 . "?page=message&forum=$forum&id=$forumpostid&pagenum=$pagenext\">NEXT </a>  ";
        echo "<a href=\"" . $_SERVER['PHP_SELF']
                 . "?page=message&forum=$forum&id=$forumpostid&pagenum=$totalpages\">>></a>  </center>";
        }
    else
        {
        echo("NEXT </center> <br />");
        }
    ?>

 

As you can see if on pahe 1 it echos the topic starter.... anything more it doesnt and thats why i start it from number 2.

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.