Results 1 to 5 of 5

Thread: PHP Script for last messages

  1. #1
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Script for last messages

    If a script like "Latest 10 messages in forum" exist (like the SMF bulletin board one) i will ask someone to share it with me or tell me how to make it

    P.S. I am sure that there is such and that in the PHP script there is something with MySQL but i can figure out what exactly i tried with searching the SMF files for it but no success...

    Edit: Uhhh sorry .. wrong board ... anyway if someone know please tell me
    Last edited by jaffyy; 09-30-2007 at 02:01 PM.

  2. #2
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    anyone... I need this script to.. but with some forums its different...

    what you have to do is poll from the mysql that ASC order...

    i think but im not sure how to write this for my forum..
    Hey new design new look, goto xudas for personal webdsign help.. (:

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For any general questions-- http://php-mysql-tutorial.com
    Should be a good intro.

    For the last ten messages, it should be fairly simple.

    SELECT * FROM `messagestable` LIMIT 10 ORDER BY `id` DESC'

    That's the query, after you have connected, then you will loop through the results and display them. (See tutorial.)

    messagestable is where the messages are stored. Not sure what that is on all board systems. ORDER BY `id` is to get the right order, as opposed to random. Just DESC might work, but better to be safe. `id` is the standard name for the number field and probably set to auto_increment, so that gets higher with every post.

    Now, you'll end up, after looping, with $row['value'] for each column in the database for the rows.

    So, $row['message'] might be the message contents. Just echo that. I don't know what names the forum has assigned the columns, but that's easy enough to figure out.

    You could use print_r($row) if you want to just find out what all of the data is or you could just log in through phpmyadmin, etc.

    One note-- $row['user'] (or similar name) may not be a username, but an id. This id refers to an item in the `users` table in the database so that the username can change, but the id will always refer to it.
    If this is the case, as would be with a well designed board, you will need to do a second query for SELECT `name` FROM `users` WHERE `id`= $row['id'].
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Here this is something I used.. whitch will be different...

    Code:
    <?php 
    include "connect.php";
    
    
    $blog_postnumber = 5; //how many posts you want to show...
    if(!isset($_GET['page'])) {    $page = 1;}else {    $page = (int)$_GET['page'];}$from = (($page * $blog_postnumber) - $blog_postnumber);
    $getthreads="SELECT * from forum where parentid='0' order by lastrepliedto desc LIMIT $from, $blog_postnumber";
    $getthreads2=mysql_query($getthreads) or die("Could not get threads");while($getthreads3=mysql_fetch_array($getthreads2)){  $getthreads3[title]=strip_tags($getthreads3[title]);    
    print "<ul>
    <li><A href='forums/forums/message.php?id=$getthreads3[postid]'>$getthreads3[title]</a><BR></ul>";
    }
    
    ?>
    Hey new design new look, goto xudas for personal webdsign help.. (:

  5. #5
    Join Date
    Aug 2007
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks both for the info That was really useful for me

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •