我必须从数据库中的行中重置特定字段的列。我正在使用MYSQL,并且在数据库表中给了多个字段,例如

1)  Sr. Number
2)  Serial Key
3)  Activation Date
4)  Valid From Date
5)  Valid Till Date
6)  Name
7)  Device ID
8)  Activity Count


我做了一种提取数据库条目的表格。在每次输入后,我都给了复位按钮,单击它必须从数据库中复位串行密钥和设备ID。我有一个建议可以指向高级编号。但是我不知道要重设这两列。其中1位于2号位置,另一个位于7号位置。您的建议将是必要的,如果您知道任何示例,请提出建议。

echo "<table align='center' id='tbl' border='1' >"; // start a table tag in the HTML
echo "<tr><th>id</th><th>device_id</th><th>serialkey</th><th>firstname</th><th>created_on</th><th>keygenerated_on</th><th>modify_on</th><th>expiry_date</th><th>active</th><th>delete</th></tr>";

while($row = mysql_fetch_array($query)){   //Creates a loop to loop through results

echo "<tr><td>" . $row['id'] . "</td><td>" . $row['device_id'] . "</td><td>" .$row['serialkey'] . "</td><td>" .$row['firstname'] . "</td><td>" .$row['created_on'] . "</td><td>" .$row['keygenerated_on'] . "</td><td>" .$row['modify_on'] . "</td><td>" .$row['expiry_date'] . "</td><td>" .$row['active'] . "</td><td><a href='display.php?del=0&id=".$row['id']."'>delete</a></td></tr>";  //$row['index'] the index here is a field name


这是我用于删除的示例代码。请建议我重设。

还附有屏幕截图

最佳答案

在列表中(如屏幕快照所示),而不是放置“删除”链接,

<a href="some_script.php?reset_id='".$row['id']."' "><button type="button">Reset</button></a>


在some_script.php中

   <?php

    $reset_id=$_GET['reset_id']; //consider sanitizing the data

    $query="update <the_table_name> set `serial key` = NULL, `device id`= NULL where id = '".$reset_id."' "; //assuming reset mean setting to NULL. Replace <the_table_name> with the table name you are working with

    $con=mysqli_connect("yourhost","db_username","db_password","your_db_name");
    if(!mysqli_query($con,$query))
    {
        //error
    }

//else you did it

关于php - 我如何使用php从表中的一行重置特定字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16895842/

10-11 00:28
查看更多