在mysqli_fetch_assoc输出中选择要删除的特定字段

时间:2017-08-30 09:59:23

标签: php mysql

我正在编程网站,我在选择要在我的查询中删除的字段时遇到问题。 这就是我所做的。

<?php 
$qryprod = "SELECT * FROM product WHERE username = 
'".$_SESSION['username']."' ORDER BY id DESC";
$prodres = mysqli_query($con, $qryprod);
if (mysqli_num_rows($prodres) > 0) {
    while ($prodview = mysqli_fetch_assoc($prodres)) {
        echo '
            <div class="col-lg-3 col-xs-6 col-sm-4 col-md-3">
              <div class="panel panel-default">
              <div class="panel-body">
                <img src="pictures/maxresdefault.jpg" class="img-responsive 
center-block">';
                ?><?php echo '<div class="row"><div class="col-md-2">Name:
</div><div class="col-md-10">'.$prodview['product_name'].'</div></div><div 
class="row"><div class="col-md-4">Stock:'.$prodview['product_stock'].'</div>
<div class="col-md-8">Price:'.$prodview['product_price'].'</div></div><div 
class="row"><div class="col-md-4">Size:'.$prodview['product_size'].'</div>
<div class="col-md-8">Brand:'.$prodview['product_brand'].'</div></div>
              </div>
              <div class="panel-footer">
                <button class="btn btn-primary"><i class="glyphicon 
glyphicon-open"></i></button>
                <button class="btn btn-danger pull-right"  data-
toggle="modal" data-target="#deleteModal"><i class="glyphicon glyphicon-
remove"></i></button>
              </div>

              </div>
            </div>
        ';
    }
}
?>

请注意,我查询了数据库中的所有项目等于$ _session ['username']。显示它没有问题。 问题在于删除部分。因为我只是查询所有它来显示它,我想从我制作的显示中删除一个。

这是我要删除的查询。

<!-- Change Delete Modal content-->
<div id="deleteModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;
</button>
    <h4 class="modal-title">Delete item</h4>
  </div>

  <div class="modal-body">
  <?php $qryprod = "SELECT * FROM product WHERE username = 
'".$_SESSION['username']."' ORDER BY id DESC";
$prodres = mysqli_query($con, $qryprod);
if (mysqli_num_rows($prodres) > 0) {
    $prodview = mysqli_fetch_assoc($prodres));
    }
      ?>
  <h4>Are you sure to delete <?php echo $prodview['product_name'] ?>?</h4>
    <form method="POST" action="store.php">
    <input type="submit" name="yes" value="Yes" class="btn btn-default btn-
lg">
    <button type="button" data-dismiss="modal" class="btn btn-default btn-lg 
pull-right">Cancel</button>
      </form>
  </div>
 </div>
  <?php if (isset($_POST['yes'])) {
 $qry ="DELETE FROM product WHERE username = '".$_SESSION['username']."' ";
 $qryres = mysqli_query($con,$qry);
 }
 ?>
  </div>
</div>

是否有某种方法可以选择要删除的所需面板?

0 个答案:

没有答案