MyBB Community Forums

Full Version: Help needed with query fetching latest posts?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on a plugin that will return threads which have been replied to within the last 24 hours by I have issue?

$timesearch = TIME_NOW - 86400;
	   $query = $db->query("
	   SELECT p.dateline, p.tid, t.tid, t.replies, t.views, t.fid, t.subject AS threadsubject, t.lastpost AS threadlastpost, t.lastposter, t.dateline AS threadage, t.lastposteruid, f.name AS name, u.username, u.usergroup, u.displaygroup
	   FROM ".TABLE_PREFIX."posts p
       LEFT JOIN " . TABLE_PREFIX . "threads t ON (t.tid = p.tid)
	   LEFT JOIN ".TABLE_PREFIX."forums as f ON (f.fid = t.fid)
	   LEFT JOIN " . TABLE_PREFIX . "users AS u ON (t.lastposteruid = u.uid)
	   {$fids} 
	   WHERE p.dateline >= $timesearch
       group BY p.tid DESC
		LIMIT 100
	   ");

Issue #1. Don't understand why p.dateline >= $timesearch is working instead of p.dateline <= $timesearch
I mean post date-line has to be lower than the time-search?

Issue #2.
Trying to add NEW: prefix to new posted thread but it juts won't show?

$cutoff = TIME_NOW - 86400;
		  if($row['threadage'] <= $cutoff)
		{
			
			$newprefix = "<span title=\"Thread posted within the last 24 hours\" class=\"newprefix\">NEW: </span>";
		}
$timesearch in the example you provided is an unix timestamp from 24 hours ago. Thus, if you want to return posts from the last 24 hours, their timestamp would be higher than the one computed.
The same thing with the second code.
Thanks buddy that explains the first code!

I can't make this one work!

Like this shows on all threads
$cutoff = TIME_NOW - 86400;
          if($row['threadage'] <= $cutoff)
        {
            
            $newprefix = "<span title=\"Thread posted within the last 24 hours\" class=\"newprefix\">NEW: </span>";
        }
Like this shows on all except new ones?
$cutoff = TIME_NOW - 86400;
          if($row['threadage'] >= $cutoff)
        {
            
            $newprefix = "<span title=\"Thread posted within the last 24 hours\" class=\"newprefix\">NEW: </span>";
        }

I think I will have to create a new query to threads table?

Here is the code that compiles the link?

$recentposts .= '
		   <td class="trow1">'.$newprefix.' '.$prefix.'<a href="'.$threadlink.'" title="'.$row["threadsubject"].'"><strong>'.$threadsthreadsubject.'</strong></a></td>


Looks like nailed it with this:

if(TIME_NOW - $row['threadage'] >= 86400)
		{
			
			$newprefix = "";
		}
		else
		{
			$newprefix = "<span title=\"Thread posted within the last 24 hours\" class=\"newprefix\">NEW: </span>";
		}

Please check me?