The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
time/date limit in query
i'm trying to display the last threads in forumhome.
does anyone knows how can I set time/date limit in the query so it will get the latest threads in X Days \ Hours. If i dont do that it will look in the entire table that will cause an overload in the server. PHP Code:
|
#2
|
||||
|
||||
$cut = time() - 60*60*X*Y;
where X is the number of hours and Y is the number of days.. You're basically counting the number of seconds (60 seconds * 60 minutes * X hours * Y days) and subsctracting from the current time so you get a date in the past.. then you'd add a condition to your query: AND thread.dateline > $cut |
#3
|
|||
|
|||
can u please write down where I have to add this?
PHP Code:
|
#4
|
|||
|
|||
ok I figured it out...
but one thing though $cut = 60*60*24*3; does this mean it will show the last threads in the last 3 days OR in the last 3 days+24 hours+60 min+60 sec because if i write 0*0*0*3 its not working. and also, do u know how can I get the forum name which the thread exist? what should I add.. thanks for your help! |
#5
|
||||
|
||||
Quote:
|
#6
|
||||
|
||||
to get the forum name you'll need to join the forum table USING(forumid) which is equal to ON(thread.forumid=forum.forumid)
|
#7
|
|||
|
|||
Link14716 thanks for the explanation
rake, I'm getting database error when adding those lines I added PHP Code:
here is the code, just tell where to add the thing u wrote PHP Code:
like this is the thread title: PHP Code:
|
#8
|
|||
|
|||
Zurih, did you manage to get his working.. If so, would you be kind enough to post what changes you made to the original mod?
|
#9
|
||||
|
||||
Hi zurih,
Please note that operators like "||" and "&" are grandpa segments of code... toss them really fast and replace them with the regular used ones. About the time cut, this is really easy. All you have to do in your query is set a timecut, in this way you don't do a full table scan... for example: Code:
$threadbits = ''; $threadmaxtime = 2 // <-- no. of days here $threadcut = time() - (86400 * $threadmaxtime); if ($activethread) // <-- condition here { // twisted condition to show the max number of threads, after the tables were partially scanned // just in case you have to many results... $threadmaxnumber = iif ($threadmax != 0 , 'LIMIT ' . $threadmax , ''); // notice the partial table scan based on "lastpost" time limit, // that will ease the server quite a lot... $threads = $DB_site->query(" SELECT threadid, forumid, title, replycount, postusername, postuserid, lastpost, views FROM thread WHERE $iforumperms AND lastpost >= $threadcut AND visible = 1 AND open <> 10 ORDER BY lastpost DESC $threadmaxnumber "); // it's time to roll out the results... while ($thread = $DB_site->fetch_array($threads)) { $thread['title'] = unhtmlspecialchars($thread['title']); $thread['title'] = xhtml_clean($thread['title']); if ($threadmaxchars != 0 and strlen( $thread['title']) > $threadmaxchars) { $thread['title'] = substr($thread['title'] , 0 , $threadmaxchars - 2) . '...'; } $thread['time'] = vbdate($timeformat , $thread['lastpost']); $thread['date'] = vbdate($dateformat , $thread['lastpost']); eval('$threadbits .= "' . gettemplate('home_threadbit') . '";'); } $DB_site->free_result($threads); unset($thread); } With my example, it should take you only few minutes to adapt it to the VB3 code, as Stefan used to say in the good old days. Cheers. |
#10
|
|||
|
|||
Thanks for the reply teck
I have couple of questions... Right now, this is my LATEST THREADES code in index.php: PHP Code:
PHP Code:
what I have to replace with your code? Thanks ! |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|