我正试图获得总重量'对于角色携带的物品。我这样做是通过选择characteritem表中的项目数量并比较项目表中设置的权重,并通过iid(项目ID)列加入它们
我尝试了很多不同的方法无济于事,所以我查了一下join语句。我遇到的问题是为什么$ result会返回bool(false),然后我怎么能在之后得到权重。
以下是我目前正在处理的代码:
*
SQL现在运行正常。我有重量和数量,并得到了个人的结果。如何为$ itemtotal获取值一起添加?
$sql = "SELECT *
FROM `characteritem` WHERE `owner` = '$user'
INNER JOIN item ON characteritem.iid=item.iid";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
$iid = $row['characteritem.iid'];
$quantity = $row['characteritem.quantity'];
$itemweight = $row['item.itemweight'];
$itemtotal = $itemweight + $itemweight;
echo $itemtotal;
}
}
var_dump($result);
答案 0 :(得分:0)
Your SQL sintax is wrong, try
$sql = "SELECT *
FROM `characteritem`
INNER JOIN item ON characteritem.iid=item.iid
WHERE `owner` = '$user'";
答案 1 :(得分:0)
试试这个
$sql = "SELECT *
FROM `characteritem`
INNER JOIN item ON characteritem.iid=item.iid" WHERE `owner` = '$user';
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
$iid = $row['characteritem.iid'];
$quantity = $row['characteritem.quantity'];
$itemweight = $row['item.itemweight'];
$itemtotal = $itemweight + $itemweight;
echo $itemtotal;
}
}
var_dump($result);