Log in

View Full Version : Help with porting over latest postid/threadid


freakyshiat
10-08-2005, 05:01 AM
I need to port over the latest threadid/postid on index page from 3.0.x to 3.5.x. The code below worked fine in 3.0.x, can someone help me port it to 3.5.x? I can via paypal, please pm me.


$newestthreadidq = $DB_site->query("
SELECT threadid
FROM thread
ORDER BY threadid DESC
LIMIT 1
");
$newestthreadid = $DB_site->fetch_array($newestthreadidq);
$newestpostidq = $DB_site->query("
SELECT postid
FROM post
ORDER BY postid DESC
LIMIT 1
");
$newestpostid = $DB_site->fetch_array($newestpostidq);
$formattedthreadid = number_format($newestthreadid[threadid]);
$formattedpostid = number_format($newestpostid[postid]);

Colin F
10-08-2005, 08:34 AM
If you just want that code to work with 3.5, use this:

$newestthreadidq = $db->query_read("
SELECT threadid
FROM thread
ORDER BY threadid DESC
LIMIT 1
");
$newestthreadid = $db->fetch_array($newestthreadidq);
$newestpostidq = $db->query_read("
SELECT postid
FROM post
ORDER BY postid DESC
LIMIT 1
");
$newestpostid = $db->fetch_array($newestpostidq);
$formattedthreadid = number_format($newestthreadid[threadid]);
$formattedpostid = number_format($newestpostid[postid]);

Andreas
10-08-2005, 10:24 AM
Better

$newestids = $db->query_first("SELECT MAX(threadid) AS threadid, MAX(postid) AS postid FROM " . TABLE_PREFIX . "post");
$formattedthreadid = number_format($newestids['threadid']);
$formattedpostid = number_format($newestids['postid']);


1 Query instead of 2, no sorting, no table or index scan :)

freakyshiat
10-08-2005, 06:26 PM
woohoo!!! thank you all :)