doudao1922 2017-08-30 09:59
浏览 47

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

im in the middle of programming a website and i have a problem in selecting the field i want to delete in my query. this is what i made.

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

notice that I queried all the item from the database equal to the $_session['username'].there is not a problem in displaying it. the problem goes in the deleting part. since i just queried all of it to display it, i want to delete a one from the display i made.

and this is my query to delete.

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

is there somehow a way to pick the desired panel to be deleted?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
    • ¥15 cs loadimage运行不了,easyx也下了,没有用
    • ¥15 r包runway详细安装教程
    • ¥15 Html中读取Json文件中数据并制作表格
    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥20 关于变压器的具体案例分析