如何捕获连续的值

时间:2014-07-25 10:12:30

标签: php

我有一个动态表,我想确保在按下删除按钮时,您必须删除数据库表中的相应值。

1 个答案:

答案 0 :(得分:0)

您必须使用下面的代码获取ID并使用锚标记来引用 your_script.php 来处理与包含数据ID的变量ID相关联的删除

$query  =   mysqli_query($your_connection, "SELECT * FROM your_table") or exit(mysqli_error);

while($rows =mysqli_fetch_array($query)):   //fetch data from the table

   $id      =   $rows['id'];                //get id of specific data 
   $product =   $rows['product']; 
   $seller  =   $rows['seller']; 
   $quant   =   $rows['quantity']; 
   $price   =   $rows['price']; 


   echo "<tr>";
        echo "<td>" . $product . "</td>";
   echo "</tr>";

   echo "<tr>";
        echo "<td>" . $seller  . "</td>";
   echo "</tr>";

   echo "<tr>";
        echo "<td>" . $quant   . "</td>";
   echo "</tr>";

   echo "<tr>";
        echo "<td>" . $price   . "</td>";
   echo "</tr>";


   //anchor tag href to your_script.php with the variable $id attached to it then use javascript to confirm delete or not
   echo "<tr>";
         echo "<td>     
            <a href=\"your_script.php?id=$id\" onClick=\"javascript:return confirm('Are you sure you want to delete this product?')\">Delete</a> <td>";
            echo </td> ";           
   echo "</tr>";

endwhile;