Jump to content

Link to last post?


MishieMoo

Recommended Posts

Okay so I have a forum and I'd like to put a link in there so that I can go to the #last post and voila!  The last post comes up.  This is more than simple page anchors, though.  I can do those in my sleep.  I'm listing my posts via mysql_fetch_array() and because of that I don't know what to do to make it so that only one post has that link.  Oh and I almost forgot to mention that I have pagination that displays 20 posts per page (variable is $page).  So the link also needs to go to the page that the post is on.

 

This is my code for that section

<?php 
            $tbl_name2="forum_answer"; // Switch to table "forum_answer"
            
            $sql2="SELECT * FROM $tbl_name2 WHERE question_id='$id' LIMIT $limitpage, $limit";
            $result2=mysql_query($sql2);
            $rows=mysql_fetch_array($result2);
            while($rows=mysql_fetch_array($result2)){
            ?>
                <table width="550px" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                <td>
                    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
                <tr>
                <td width="18%" bgcolor="#F8F7F1">Name</td>
                <td width="5%" bgcolor="#F8F7F1">:</td>
                <td width="77%" bgcolor="#F8F7F1"><a href="members.php?id=<? echo $rows['a_userid']; ?>"><? echo $rows['a_name']; ?></td>
                </tr>
                <tr>
                <td bgcolor="#F8F7F1"><strong>Reply</strong></td>
                <td bgcolor="#F8F7F1">:</td>
                <td bgcolor="#F8F7F1"><? echo nl2br($rows['a_answer']); ?><p align="right"><small><i>
                <?php
                if(!empty($rows['editid'])) {
                    echo 'Last edited by '.$rows['editid'].' at '.$rows['edittime'].'. '; }
                if($_SESSION['userid'] == $rows['a_userid']) {
                    echo '<a href="editanswer.php?mode=display&id='.$rows['a_id'].'">Edit</a> '; }?></i></small></p></td>
                </tr>
                <tr>
                <td bgcolor="#F8F7F1"><strong>At </strong></td>
                <td bgcolor="#F8F7F1">:</td>
                <td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
                </tr>
                </table></td>
                </tr>
                </table><br>
            <?php } ?>

 

When a user makes a post so far it registers the date and id (among other things, none useful in this situation).  I'm still pretty new to php so is there a function where I can call the highest id from a set? I feel like there is and I'm just being stupid  :P  How to handle the pages, though, I have no clue.

 

Any help would be appreciated ^_^+

Link to comment
Share on other sites

well...since it's a forum, don't you have any connection between the topic and post ?

 

somehing like "topic_id" or something, for posts...

i assume you have an unique id for the posts

 

if you do, just ose 'select <fields> from <post table> where topic_id="<the one you're interested in>" order by ID DESC' and check the first id that shows, that is the last one inserted in the database on that topic

 

for the page number, do a select count with with the same "where" clause, but without the "order by" and check the integer part of the result, there is a function, but i forgot it...

 

ex : 30/20=1.5 so page number 1 {assuming you start from page 0, if not, just add "1" to the result}

Link to comment
Share on other sites

That's not what I want.  I already have listing updated topics working and a link to the recent post that brings you to the thread page (page 1).

 

I want to have a page anchor placed so that I can click on a text link to go to the last post on a certain thread.  So that if its on page 18 you don't go to page 1, but the last post on page 18 for example.

 

It already updates what is the last post in a category, and thread.  I want a link to the latest reply.  Aka there's a link to the highest reply id in a thread id.

Link to comment
Share on other sites

Well, you could pull the highest ID from the database using SORT DESC LIMIT 0, 1.  And then if you do some calculating to figure out which page its on... divide total in thread by however many to a page... Then you can figure out what page its on... and as far as doing the page anchor... you said you can do those in your sleep ;)

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.