I have a basic messaging system set up and I m using the same query to show sent and received messages. It works very well, but I need to get the fbook field for exp and dest. I thought of creating two queries and use one if the user sent the message he is viewing and use the other query if the message has been recieved, but maybe there’s a better way.
+-----+------+------+----------+----------------+---------------------+------+
| id | exp | dest | message | msg_title | timestamp | view |
+-----+------+------+----------+----------------+---------------------+------+
| 114 | 243 | 245 | From 243 | Message to 245 | 2012-04-04 09:26:52 | 0 |
+-----+------+------+----------+----------------+---------------------+------+
Query
SELECT a.*, b.fbook FROM messages a
JOIN users b ON a.exp=b.id
WHERE a.id = 114;
Users table
+------------------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(50) | NO | | NULL | |
| fbook | bigint(64) | YES | | NULL | |
+------------------------+--------------+------+-----+---------------------+----------------+
You want to do something like this: