View Full Version : PHP Script for last messages
jaffyy
09-30-2007, 01:32 PM
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 :)
insanemonkey
09-30-2007, 08:16 PM
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..
djr33
09-30-2007, 08:43 PM
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'].
insanemonkey
10-01-2007, 03:35 AM
Here this is something I used.. whitch will be different...
<?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>";
}
?>
jaffyy
10-01-2007, 06:50 PM
Thanks both for the info :) That was really useful for me :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.