使用mysqli从数据库中检索数据 [英] Retrieve data from database using mysqli
本文介绍了使用mysqli从数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从数据库中获取数据并对其进行行处理时遇到问题,我遇到了错误. 如何使用while从数据库中获取数据并对其进行行操作.
I have a problem when I fetching data from database and row it I Got an error. How To fetch data From database using while and row it.
致命错误:在
Fatal error: Call to a member function fetch() on a non-object in
先谢谢了.
这是我的代码.
<body>
<?php
$id = $_GET['id'];
$iqry = $mysqli->prepare("SELECT itemcode,itemname,brandname,quantity FROM table_inventory WHERE id = ?");
$iqry->bind_param('i', $id);
$iqry->execute();
$iqry->bind_result($itemcode,$itemname,$brandname,$quantity);
$res = $iqry->store_result();
while ($row = $res->fetch()){
$itemcode = $row['itemcode'];
$itemname = $row['itemname'];
$brandname = $row['brandname'];
$quantity = $row['quantity'];
}
?>
<form method="post" name="increasing" action="save.php">
<table>
<tr><td>Itemcode</td><td>:</td><td><input type="text" name="itemcode" required="required" value="<?php echo $itemcode; ?>">/></td></tr>
<tr><td>Itemname</td><td>:</td><td><input type="text" name="itemname" required="required" value="<?php echo $itemname; ?>"/></td></tr>
<tr><td>Brandname</td><td>:</td><td><input type="text" name="brandname" required="required" value="<?php echo $brandname; ?>"/></td></tr>
<tr><td>Quantity</td><td>:</td><td><input type="text" name="quantity" required="required" value="<?php echo $quantity; ?>"/></td></tr>
<tr><td></td><td></td><td><input type="submit" class="myButton" value="Save"/></td></tr>
</table>
</form>
<body>
推荐答案
您似乎混淆了mysqli_stmt
和mysqli_result
方法.
尝试进行以下更改:
-
LIMIT
您的结果集为一个
... FROM table_inventory WHERE id = ? LIMIT 1
与mysqli_stmt
粘在一起,因为您似乎对此更加了解
Stick with the mysqli_stmt
as you seem to be further along with that
$iqry->bind_param('i', $id);
$iqry->execute();
$iqry->bind_result($itemcode, $itemname, $brandname, $quantity);
if (!$iqry->fetch()) {
throw new Exception('No results found for ID ' . $id, 404);
}
// You can now use $itemcode, $itemname, $brandname and $quantity,
// they will all be set
?>
<form ...
这篇关于使用mysqli从数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文