Jump to content


This topic is now archived and is closed to further replies.


table joins and implementation in php

Recommended Posts

I have my current query,


$query = \"SELECT id,title,newstext,\" .

\"DATE_FORMAT(postdate, \'%Y-%m-%d\') as date \" .

\"FROM news ORDER BY postdate DESC\";


but i need to also add a poster_id to the news table query and join that with a users table with an id and username. If i remember correctly i just have to add the table name and a period before the field, but how do i do it for the postdate?

Also, when I go to output the username from the users table in PHP, do i have to do $row[username], or will i have to do $row[users.username]?


any help is appreciated since i am new to table joins.

Share this post

Link to post
Share on other sites

it would be something like this




$query = \"SELECT news.id,news.title,news.newstext,users.poster_id,users.username\" .

\"DATE_FORMAT(news.postdate, \'%Y-%m-%d\') as date \" .

\"FROM news INNER JOIN users ON news.field = users.field ORDER BY news.postdate DESC\";




replacing the \"field\" with whatever field is in both tables. The array would then be $row[username], and not $row[users.username]


Hope that helps

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.