MyBB Community Forums

Full Version: Extracting the latest posts from portal.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Gonna post the final code? I was planning on doing what you did, but you got done before I started.
Well.. here it is! It still needs formatting though, so if you could put it in a nice table and maybe repost it.. that'd be great!

Here it is:

Code:
<?
include("url to functions.php");
mysql_connect('host', 'user', 'pass');
mysql_select_db('db');

    $query = mysql_query("SELECT t.*, u.username FROM threads t LEFT JOIN users u ON (u.uid=t.uid) WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.lastpost DESC  LIMIT 0, 10");
    while($thread = mysql_fetch_array($query))
    {
        if($thread['lastpost'] != "" && $thread['lastposter'] != "")
        {
            $lastpostdate = mydate("dS of F Y", $thread['lastpost']);
            $lastposttime = mydate("h:i:s A", $thread['lastpost']);
            eval("\$lastpost = \"".("<html><body><i>Last Post by:</i> <a href=forum/member.php?action=profile&uid=lastposter&tid=$thread[tid] target=center> $thread[lastposter]</a><br />
$lastpostdate $lastposttime<br /></body></html>")."\";");
        }
        else
        {
            $lastpost = "";
        }
        $thread['subject'] = stripslashes($thread['subject']);
        if(strlen($thread['subject']) > 25)
        {
            $thread['subject'] = substr($thread['subject'], 0, 25) . "...";
        }
        $thread['subject'] = htmlspecialchars($thread['subject']);
        eval("\$threadlist .= \"".("<html><body><tr>
<td class=$altbg>
<b><a href=forum/showthread.php?tid=$thread[tid] target=center> $thread[subject]</a></b><span class=smalltext><br />
$lastpost
<b>� </b>Replies: $thread[replies]<br />
<b>� </b>Views: $thread[views]
</td>
</tr></body></html>")."\";");
        if($altbg == "trow1")
        {
            $altbg = "trow2";
        }
        else
        {
            $altbg = "trow1";
        }
    }
    
    eval("\$latestthreads = \"".("<html><body><table cellspacing=0 cellpadding=0 border=0 width=100%>
<tr>
<td class=tborder>
<table border=0 cellspacing=$theme[borderwidth] cellpadding=$theme[tablespace] width=100%>
<tr>
<td class=thead><b>Latest Threads</b></td>
</tr>
$threadlist
</table>
</td></tr></table>
<br></body></html>")."\";");
    print "$latestthreads";



?>

You could probablt cut out half of that code, but im new to PHP.
I took what you had and I modified it to suit my purposes. I also made it a little easier, you can change things in the admin cp and it should still work without needing to be modified.
<?php
include("inc/functions.php"); // Path to Functions.php
include("inc/config.php"); // Path to Config.php
include("inc/settings.php"); // Path to Settings.php

mysql_connect($config[hostname], $config[username], $config[password]);
mysql_select_db($config[database]);

$query = mysql_query("SELECT t.*, u.username FROM threads t LEFT JOIN users u ON (u.uid=t.uid) WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%' ORDER BY t.lastpost DESC  LIMIT 0, 10");
while($thread = mysql_fetch_array($query))
{
if($thread['lastpost'] != "" && $thread['lastposter'] != "")
{
$lastpostdate = mydate("dS of F Y", $thread['lastpost']);
$lastposttime = mydate("h:i:s A", $thread['lastpost']);
eval("\$lastpost = \"".("<a href=$settings[bburl]member.php?action=profile&uid=lastposter&tid=$thread[tid]> $thread[lastposter]</a>")."\";");
}
else
{
$lastpost = "";
}
$thread['subject'] = stripslashes($thread['subject']);
if(strlen($thread['subject']) > 25)
{
$thread['subject'] = substr($thread['subject'], 0, 25) . "...";
}
$thread['subject'] = htmlspecialchars($thread['subject']);
eval("\$threadlist .= \"".("<tr>
<td><b><a href=$settings[bburl]showthread.php?tid=$thread[tid]> $thread[subject]</a></b></td>
<td>$lastpost </td>
<td>$thread[replies] </td>
<td>$thread[views] </td>
</tr>")."\";");
if($altbg == "trow1")
{
$altbg = "trow2";
}
else
{
$altbg = "trow1";
}
}

eval("\$latestthreads = \"".("<table border=0 cellspacing=$theme[borderwidth] cellpadding=$theme[tablespace] width=100%>
<tr>
<td><b>Thread</b></td>
<td><b>Posted by</b></td>
<td><b>Replies</b></td>
<td><b>Views</b></td>
</tr>
$threadlist
</table>")."\";");
print "$latestthreads";

?>
just recently registered. i added the this to the main area of the forum. and it doesn't seem to be showing anything by any chance do i need to add mysql information in these areas?
mysql_connect($config[hostname], $config[username], $config[password]);
mysql_select_db($config[database]);
i don't mean to double post. but im wondering if any one can help me out with this. does this code actually work and can someone assist me on what am i doing wrong?
Doesn't work for me either :'(
If you added it to the template, you can't add connection code to the template bits.
If you edited PHP files, and it's in a function, then you need to make $config global by adding
global $config;
underneath the function heading.
i have no idea what you just said decswxaqz.

What I did is take the code supplied in post #13 by TemplatesForAll and paste it in a new .php file called test1.php.
I placed test1.php in my forum root folder.

When I call the page from the browser it doesn't show anything, not even errors or warnings. Just a plain white page.

Hope that info helps? Thanks in advance.
could someone explain what does this "mod" do?

Maybe I'm interested too

Thank you guys Smile
Pages: 1 2