首页 > 解决方案 > 为消息表加入用户表

问题描述

我正在 PHP mysqli 中创建消息对话脚本。我想显示用户表中的用户名我想知道如何将消息表加入用户表。

这是我的源代码

users table

userid username
if ($stmt = $con->prepare("SELECT * from pm where (from_id=? and to_id=?) || (to_id=? and from_id=?)")){
    $stmt->bind_param('ssss', $from_id,$to_id,$from_id,$to_id);
    $stmt->execute();
}

标签: phpmysqli

解决方案


好的试试这个:

if ($stmt = $con->prepare("SELECT * FROM users INNER JOIN pm ON pm.userId=users.id WHERE from_id=? AND to_id=?")){
$stmt->bind_param('ii', $from_id, $to_id);
$stmt->execute();
}

推荐阅读