无法加入 php/mysql 中的第三个 table 以获取用户名
Can't join third table in php/mysql to get user name
我有一个工作完美的连接。但是,我需要加入名为 wp_users 的第三个 table,这样我才能访问用户显示名称。当我添加第二个连接时,根据我的尝试,我不断收到各种错误,所以我正在寻求帮助。
第三个table、wp_users有两列:
wp_users.ID,
wp_users.display_name
这是我添加第二个连接代码之前的代码,因此我可以获得结果 ID 的显示名称
//Works, but I need to join to wp_users on wp_users.ID to get display_name
$results = $dbh->prepare("select
stories.ID,
stories.SID,
stories.story_name,
stories.category,
points.ID,
points.PID,
FROM stories
JOIN points ON stories.SID=points.SID
JOIN stories ON wp_users.ID=points.ID
where (points.ID = $user_ID) and (PID = 1)");
$results->execute();
将stories
更改为wp_users
JOIN stories ON wp_users.ID=points.ID
到
JOIN wp_users ON wp_users.ID=points.ID
$results = $dbh->prepare("select
stories.ID,
stories.SID,
stories.story_name,
stories.category,
points.ID,
points.PID,
FROM stories
JOIN points ON stories.SID=points.SID
JOIN wp_users ON wp_users.ID=points.ID
where (points.ID = $user_ID) and (PID = 1)");
$results->execute();
我有一个工作完美的连接。但是,我需要加入名为 wp_users 的第三个 table,这样我才能访问用户显示名称。当我添加第二个连接时,根据我的尝试,我不断收到各种错误,所以我正在寻求帮助。
第三个table、wp_users有两列: wp_users.ID, wp_users.display_name
这是我添加第二个连接代码之前的代码,因此我可以获得结果 ID 的显示名称
//Works, but I need to join to wp_users on wp_users.ID to get display_name
$results = $dbh->prepare("select
stories.ID,
stories.SID,
stories.story_name,
stories.category,
points.ID,
points.PID,
FROM stories
JOIN points ON stories.SID=points.SID
JOIN stories ON wp_users.ID=points.ID
where (points.ID = $user_ID) and (PID = 1)");
$results->execute();
将stories
更改为wp_users
JOIN stories ON wp_users.ID=points.ID
到
JOIN wp_users ON wp_users.ID=points.ID
$results = $dbh->prepare("select
stories.ID,
stories.SID,
stories.story_name,
stories.category,
points.ID,
points.PID,
FROM stories
JOIN points ON stories.SID=points.SID
JOIN wp_users ON wp_users.ID=points.ID
where (points.ID = $user_ID) and (PID = 1)");
$results->execute();