繁体   English   中英

无法提取数据库中数据的所有列,并且只有一列可以检索

[英]Not Fetch All column in the data in database and only one can retrieve

大家好,我的查询有问题。.当我尝试以相同的结果一个数据一个且检索的结果在数据库的最后一个id上时

这是我的密码

$code = $mysqli->prepare("SELECT id,code FROM table_inventory");

$code->execute();
$code->bind_result($id,$ccode);

$res = $code->get_result();

   while ($row = $res->fetch_array()){

        $id = $row['id'];
        $co = $row['code'];
   }

<form role="form">

<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="test" class="form-control" id="exampleInputEmail3" placeholder="Enter email">
</div>
<div class="form-group">
<label for="code">Item Code</label>
<input type="text" class="form-control" id="code" placeholder="code" value="<?php echo $co; ?>">
</div>

预先感谢。

未经测试,但类似这样:

while ($row = $res->fetch_array()){

        $id[] = $row['id'];
        $co[] = $row['code'];
   }

<form role="form">

<?php
    foreach($id as $ind=>$val){ ?>
<input type="hidden" name="id" value="<?php echo $id[$ind]; ?>">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="test" class="form-control" id="exampleInputEmail3" placeholder="Enter email">
</div>
<div class="form-group">
<label for="code">Item Code</label>
<input type="text" class="form-control" id="code" placeholder="code" value="<?php echo $co[$ind]; ?>">
</div>
<?php
}
?>

顺便说一下,我猜这不是您的完整代码,因为您的PHP和HTML混在一起了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM