determine user last post?
#1
There is a lastpost row in the threads table now i wanna fetch the last one but I can't!


$q = $db->simple_select("threads", "*", "uid = 30");
    while($row = $db->fetch_array($q))
	{
	$time_check = $row['lastpost'];	
	echo $time_check;
	}


This returns all values but how to only return the last one which is the one I am interested in?

This one only returns the first Wink


$q = $db->simple_select("threads", "*", "uid = 30");
   $row = $db->fetch_array($q)

	$time_check = $row['lastpost'];	
	echo $time_check;


Please help.


I this the correct way????


$q = $db->simple_select("threads", "*", "uid = 30", array('order_by' => 'lastpost', 'order_dir' => 'DESC', 'limit' => 1));
Reply
#2
Quote:I this the correct way????

Not really.
Soporte en Español

[Image: signature.png]

Discord at omar.gonzalez (Omar G.#6117); Telegram at @omarugc;
Reply
#3
The lastpost field is the timestamp of the last post in the thread, not its id.

If you want to have the last post of a member in a particular thread, you have to look in the posts table. And to have only a last element, the MAX() function in SQL is great.
Tchat en français
Do not ask me help through PM or Discord

Reply
#4
portal.php has great example:

$query = $db->query("
 SELECT t.tid, t.fid, t.uid, t.lastpost, t.lastposteruid, t.lastposter, t.subject, t.replies, t.views, u.username
 FROM ".TABLE_PREFIX."threads t
 LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=t.uid)
 WHERE 1=1 {$excludeforums}{$tunviewwhere} AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
 ORDER BY t.lastpost DESC
 LIMIT 0, ".$mybb->settings['portal_showdiscussionsnum']
 );
 while($thread = $db->fetch_array($query))
 { }

so only need made small changes...

$query = $db->query("
 SELECT t.lastpost
 FROM ".TABLE_PREFIX."threads t
 WHERE 1=1 AND t.visible='1' AND t.closed NOT LIKE 'moved|%'
 ORDER BY t.lastpost DESC
 LIMIT 0, 5"
 );
 while($row = $db->fetch_array($query))
 {
    $time_check = $row['lastpost'];
    echo $time_check;
 }

code above will return 5 last posts because of limit.
I removed {$excludeforums}{$tunviewwhere}, but you can add, see portal.php.
i not tested and i not know if work. and mysql not my strong area. But this already has answer in inside of mybb.

So please do a little research. And stop keep asking the answer. Try it yourself to solve the issue. You will never learn that way.
Reply
#5
@martec baby thanks so much! I don't get it how is it possible to SET LIMIT to 0.5?

I am usually back-tracking MYBB source code but some times I get stuck so thank yo very much you rock!
Reply
#6
"LIMIT 0, 5" means: start with element 0 and take 5.
Support PMs will be ignored!
Reply
#7
Read: limit 5 offset 0
Tchat en français
Do not ask me help through PM or Discord

Reply
#8
cool thanks Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)