简体   繁体   中英

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

Hi everyone I have a problem with my query.. When I try To a data one by one same result and the result that retrieve is on the last id of the database

This is my codes..

$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>

Thank in advance.

Not tested, but something like this:

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
}
?>

I'm guessing this isn't your full code by the way, because your PHP and HTML are mixed in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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