php - 为消息表加入用户表
问题描述
我正在 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();
}
解决方案
好的试试这个:
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();
}
推荐阅读
- python - 有没有办法在 Python 中传递一个块参数而不首先将它定义为一个函数?
- python - 如何编写一个 lambda 函数,对从 1 到 n 的整数执行函数,其中 n 是整数?
- sql-server - 无法在我的 PC 上的 SQL Server 上运行作业
- excel - 使用 VBA 从已关闭的 Excel 工作簿中获取信息
- assembly - 如何在 Yocto 中编译 NASM 文件?
- javascript - 当前代码需要是 IIFE(自调用) - 代码工作并运行
- mysql - 有人可以解释我的触发器中的错误吗?
- reactjs - React Native Auth0 中 Android 的“YOUR_APP_PACKAGE_NAME”是什么?
- swift - DispatchGroup 做、尝试、抓住?
- pandas - AttributeError:“系列”对象没有属性“to_numeric”