简体   繁体   English

SQL查询以显示登录用户表中的值

[英]SQL Query to Display Values in Table for Logged In User

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". 我在名为“ url”的表中有一个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 logged 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. 我希望通过$ session-> username的会话值显示已登录用户的url,但尚未弄清楚如何仅为已登录用户呈现URL。

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. 提前致歉,我可能有一个错误的主意,但想向您展示我正在尝试做的事情,但是如果没有SQL语法错误,我将无法正常工作。

$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. 假设您有一个名为user_id的列,该列建立了黑白usersurls表的关系。 if that column name is named anything else replace the user_id with that column name 如果该列名已命名,则用该列名替换user_id

$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. 例如,一个user_id。 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."'";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM