我正在为人们提供销售商品和提供产品报价的应用程序。如果用户查看他们的产品报价,它必须包含每个报价信息,以及该报价的每个用户的详细信息。首先告诉数据库需要查询哪些offer,通过ajax onclick 函数激活。(我知道了)其次,查询 OFFERS 表以获取状态为“o”且 PID 等于$_GET['pid'](5) 的商品。OFFERS------------------------------| uid | pid | status | price |------------------------------| 5 | 5 | o | 49 || 7 | 5 | o | 45 |------------------------------然后根据每个offer查询USERS表的信息?之后,对于每个结果,根据 UID,查询用户表以获取与用户相关的信息。USERS-------------------------------------| uid | fname | lname | rating |-------------------------------------| 5 | John | Jan | 4.3 || 7 | Mark | Mull | 4.2 |-------------------------------------这是我对数据库的 PHP 语句的片段。$stmt = $conn->prepare('SELECT offerdate,price FROM offers WHERE pid=? AND status=?');$o = 'o';$stmt->bind_param('is', $_POST['pid'],$o);$stmt->execute();$stmt->bind_result($offerdate,$price);我需要的另一个声明$stmt = $conn->prepare('SELECT fname,lname,rating, FROM users WHERE uid=?');$stmt->bind_param('i', );$stmt->execute();$stmt->bind_result($fname,$lname,$rating);任何帮助都会很棒,谢谢!
2 回答
青春有我
TA贡献1784条经验 获得超8个赞
执行连接两个表的单个查询。
SELECT offerdate, price, fname, lname, rating
FROM offers
INNER JOIN users ON users.uid = offers.uid
WHERE offers.pid = ? AND offers.status = ?
慕码人8056858
TA贡献1803条经验 获得超6个赞
您可以在一个带有连接的查询中获得该结果:
select o.offerdate, o.price u.fname, u.lname, u.ratingfrom offers oinner join users u on u.uid = o.uid where o.pid = ? and o.status = ?
- 2 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消