MyBB Community Forums

Full Version: get a time stamp for a PM that was sent from user X to user Y
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I assume it's possible to get a time stamp as to when a PM was sent by user X to user Y...I just don't know the query

is this possible?
$uid1 = 3; // Sender's user id
$uid2 = 45; // Receiver's user id
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '$uid1' AND `toid` = '$uid2';";

If you want the latest one only then:

$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '$uid1' AND `toid` = '$uid2' ORDER BY `dateline` DESC LIMIT 1;";
(2013-12-06, 07:15 PM)effone Wrote: [ -> ]
$uid1 = 3; // Sender's user id
$uid2 = 45; // Receiver's user id
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '$uid1' AND `toid` = '$uid2';";

If you want the latest one only then:

$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '$uid1' AND `toid` = '$uid2' ORDER BY `dateline` DESC LIMIT 1;";

that doesn't work.

I replaced $uid1 and $uid2 with the sender and receiver uid.
Is there any error you are getting?
Is your DB table prefix 'mybb_' ?
(2013-12-06, 09:29 PM)effone Wrote: [ -> ]Is there any error you are getting?
Is your DB table prefix 'mybb_' ?

yes, the prefix is mybb_

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND ' at line 1

here's the query I'm running:
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4';";
there is a typo
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4'";
Well, if you are using this in a plugin of MyBB; try doing this way:

$uid1 = 3; // Sender's user id
$uid2 = 45; // Receiver's user id
$query = $db->query("SELECT dateline FROM ".TABLE_PREFIX."privatemessages WHERE fromid='".$uid1."' AND toid='".$uid2."'");

while($time_stp = $db->fetch_array($query)){
    // Do something here ...
    print_r($time_stp);
}

It should work.

(2013-12-07, 04:53 AM).m. Wrote: [ -> ]there is a typo
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4'";

If you are talking about the query terminator then as much I know the semicolon character is a statement terminator and it is a part of the ANSI SQL-92 standard. Though it is optional for single SQL queries.
I placed two terminators one for SQL and other for PHP.
(2013-12-07, 04:53 AM).m. Wrote: [ -> ]there is a typo
$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4'";

still a bad query:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$query = "SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND ' at line 1

I figured it out by running this:

SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4' 

I guess the original problem was the assumption that I was wanting to get the data via a plugin rather than running a query in mysql..

anyhow, thanks all!
Check again, I guess 'uid' should be 'fromid'.
Also, are you sure about marking the correct answer?
(2013-12-07, 05:20 AM)effone Wrote: [ -> ]Check again, I guess 'uid' should be 'fromid'.
Also, are you sure about marking the correct answer?

I unmarked it as it is technically wrong.

this was the correct query in mysql:

SELECT `dateline` from `mybb_privatemessages` WHERE `uid` = '321' AND `toid` = '4'
Pages: 1 2