Helpful Information
 
 
Category: vBulletin.org Forum
Most Recent Threads?

Is there a hack to show the most recent 5 threads on my main index.html (or shtml) page for my site, linking to the respective posts?

I have seen this on other forums such as UBB, but I have little knowledge in mySQL programming, so I don't know how to pull this info out.

Can anyone point me in the direction of a hack, or help with the programming?

Thanks In Advance.

i would like this too

thx

I'm taking it that no-one knows any way to do this?

Comments aappreciated.

You could use the query:

SELECT threadid, dateline, title FROM thread WHERE visible=1 AND open=1 AND dateline!=4294967295 ORDER BY dateline DESC LIMIT 5;

But you would probably want to do some permissions checking for each.

Here is something to get you started:

Visit http://www.php.net. Read through the manual (you can skip the parts for most of the modules, just be sure to read the MySQL one). If you have done any programming before it won't be bad. Then go to http://www.mysql.com and read the documentation there. Then just go look at the /forum/index.php and just see if you can figure out how it displays the forums. Then check out /forum/forumdisplay.php and see how it displays the threads. Some other files to look at would include /forum/global.php, /forum/admin/global.php and /forum/admin/functions.php. Then you should have a pretty good idea of how to accomplish this, its not that difficult.

I am going to give this a go, but I havent done any PHP/SQL before, so I might struggle.

If I manage to do this I will post it up here, if anyone else manages to complete a version of this, it would be appreciated too...

I tried using this code as a new file...

<?php
require("global.php");

$db_link = @mysql_pconnect("$dbservername", "$dbusername", "$dbpassword");
mysql_select_db ("$dbname", $db_link);

$query = mysql_query("SELECT threadid, dateline, title FROM thread WHERE visible=1 AND open=1 AND dateline!=4294967295 ORDER BY dateline DESC LIMIT 5");

while($row = mysql_fetch_array($query))
{
$username = $row["title"];

print("$title");
}

?>

But that gave me the error:

Warning: Supplied argument is not a valid MySQL-Link resource in /home/bombout/public_html/board/posts.php on line 5

.. when I ran posts.php (my new file name)

Anyone got any ideas?

I would much rather help someone that is at least trying to do it on their own then just write it for someone.

The problem you have here is that you are trying to connect to the MySQL db on your own, let the vB engine do that. If you look in admin/db_mysql.php there is already a class designed for this, (Plus if you look in any vB file you can see this being used). Whenever you load the global.php several things happen automatically. First as persistant connection is opened to the db server, so no need for that. Next variables are for who the person is and session stuff. When reading through the files be sure you also read through any included files. What I did when I began writing the hacks (granted I only started two weeks ago) I printed out all the common files, global.php, functions.php, session.php and then the index.php from the forum dir. Then I just started at the global.php and read through. If I came to a new function that wasn't a PHP function I found that function definition and parsed it in my mind. Doing this will just give you a general understanding of how it all works.

Now what you are trying to do would be changed to this.


<?php

chdir( "./forum");
require( "./global.php");
chdir( ".." );

/* Note: anytime you include global.php you must include it at the beginning
before any output it sent. The way around this would be to set output buffering
in the php.ini file, however a better practice would be to just get in the habbit of
including it before you send any PHP or HTML output. */

?>
<HTML>
<BODY>

<?php

$recentThreads = $DB_site->query( "
SELECT threadid, dateline, title
FROM thread
WHERE visible=1 AND open=1 AND dateline!=4294967295
ORDER BY dateline DESC LIMIT 5"
);

while ( $thread = $DB_site->fetch_array( $recentThreads ))
{
$output .= "<a href=\"/forum/showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]\">$thread[title]</a><br>";
}

dooutput( $output );

?>
</BODY>
</HTML>


Now this is still incomplete. You would want to add permissions checking to the thread, look at the forumdisplay.php and index.php files. You will want to first check the user has permission on the forum the thread is in (use the forumid element of the thread table) and then make sure the thread is visible ( visible element of the thread table).

Thank you.

I have modified it slightly to work along with my board, but it was basically getting the topics to be linked to the board which I was finding the trouble with in the end :D

Thank You Again, and I will continue to work with it :D










privacy (GDPR)