$sql = \"select body, stamp from posts where user_id = \'$userid\' order by stamp desc\";
NOTE: the above query works fine. What I want to do is also s
You can use table name to select the columns. Ex:
$Query = "select table1.body, table1.stamp, users.username from posts, users where user_id = '$userid' order by stamp desc";
But, this method is not good in performance.
The best method is:
$Query = "SELECT table1.body, table1.stamp, users.username
FROM posts
INNER/LEFT/RIGHT JOIN users
ON users.user_id = '$userid' AND users.user_stamp = stamp.stamp_id
All the tables must be related.
Greetings,
$sql = "select body, stamp from posts , username from users where user_id = '$userid' order by stamp desc";
I just corrected the syntactical error in your query... that is the AND keyword should be replaced by ,
.
$sql = "SELECT p.body,p.stamp,u.username from posts p LEFT JOIN users as u ON (p.user_id = u.user_id) WHERE user_id = '$user_id' ORDER BY p.stamp DESC";
should do it