我有一个我完美工作的联接。但是,我需要加入第三个名为wp_users的表,以便我可以访问用户显示名称。当我添加第二个连接时,我会不断收到各种错误,这取决于我尝试的内容,所以我正在寻求帮助。
第三个表,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();
答案 0 :(得分:0)
将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();