通过单击其他按钮从隐藏字段中获取价值

时间:2019-03-02 09:16:20

标签: php

我有不同的产品,它应该具有视图描述,当单击该视图时,将弹出一个模式并显示为其指定的描述。但是,我首先尝试获取隐藏字段的值进行测试。当我单击第一个按钮时,它显示隐藏字段的值,但是当我单击其他按钮时,它保持不变。例如: 按钮1(视图说明): 按钮2(视图说明): 当我单击按钮1时,它将在模式中显示隐藏字段的值为1。但是,当我单击按钮2时,它将再次在模式1中显示。我应该怎么做才能通过单击按钮来获取隐藏字段的值?这是我的代码:

<div id="display">
             <?php


                include('database_connection.php');

                $query = "SELECT * FROM tbl_product ORDER BY id DESC";

                $statement = $connect->prepare($query);

                if($statement->execute())
                {
                    $result = $statement->fetchAll();
                    $output = '';
                    foreach($result as $row)
                    {
                        $output .= '
                        <form method="post">
                        <div class="col-md-3" style="margin-top:12px;">  
                            <div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px; height: 383px;" align="center">
                                <img src="images/'.$row["image"].'" class="img-responsive" /><br />
                                <h4 class="text-info">'.$row["name"].'</h4>
                                <h4 class="text-danger">$ '.$row["price"] .'</h4>
                                <input type="text" name="quantity" id="quantity' . $row["id"] .'" class="form-control" value="1" />
                                <input type="hidden" name="hidden_name" id="name'.$row["id"].'" value="'.$row["name"].'" />
                                <input type="hidden" name="hidden_price" id="price'.$row["id"].'" value="'.$row["price"].'" />
                                <input type="button" name="add_to_cart" id="'.$row["id"].'" style="margin-top:5px;" class="btn btn-success form-control add_to_cart" value="Add to Cart" />
                                <input type="hidden" name="getprod" id="getprod" value="'.$row["id"].'"/>
                                <input type="button" name="description" data-toggle="modal" data-target="#myModal" style="margin-top:5px;" class="btn btn-success form-control description" value="View Description" />

                            </div>
                        </div>
                        </form>
                        ';
                    }
                    echo $output;
                }


                ?>

        </div>


<!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
              </div>
              <div class="modal-body">

               <?php $prod = $_POST["getprod"]; ?>

                <h1><?php echo $prod; ?></h1>

              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
              </div>
            </div>
          </div>
        </div>

    </div>
</body>

0 个答案:

没有答案