I am just starting out, very much a rookie and any help would be greatly appreciated. I have a list of URLs in a table called "url". I have another table called "users" and in that table a column named "username" which list the users of the site. I am looking to display urls for the lo开发者_运维知识库gged in user via a session value of $session->username but have not yet figured out how to only render URLS for the logged in user.
I apologise in advance, I may have the wrong idea but wanted to show you what I was attempting to do but am not able to get to work properly without SQL syntax errors.
$result = $db->query('SELECT * from urls, users INNER JOIN username ON
$session->username');
Thank you very much
Assuming you have a column named user_id
which is making a relation b/w users
and urls
table. if that column name is named anything else replace the user_id
with that column name
$result = $db->query('SELECT * from users u JOIN urls ur
ON u.username = ur.username
WHERE u.username="'.$session->username.'"');
You need to use the index connection your urls to your user. An user_id for example. This would give you an query like:
$sQuery = "SELECT * FROM users
INNER JOIN urls ON urls.user_id = users.user_id
WHERE users.username = '".$oSession->username."'";
精彩评论