简体   繁体   English

回显每一行上的删除按钮

[英]delete button on each row that echo

every time user insert information and click add button, new data will store to database and echo into this table 每次用户插入信息并单击添加按钮时,新数据将存储到数据库并回显此表

table

<tr>
    <td colspan="4" align="right">
        <input  type="image" value="image"  src="images/btn_add.gif" onclick="action_1()">
    </td>
</tr>
<tr>
    <td colspan="2" class="title_all_u">Family Member Summary</td>
</tr>
<tr>
    <td>
        <?php 
            $query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
            $result = mysql_query($query) or die(mysql_error());
            echo "<table border='1'>
                    <tr>
                        <th>Family Type</th>
                        <th>Name</th>
                    </tr>";
                while($row = mysql_fetch_array($result))
                {
                echo "<tr>";
                echo "<td>" . $row['family_child_type'] . "</td>";
                echo "<td>" . $row['family_child_name'] . "</td>";
                echo "</tr>";
                }
            echo "</table>";
        ?>
    </td>           
</tr>   

and this is insert query 这是插入查询

if ( $action ==3 ) {
   $spouse_type = $_POST['spouse_type'];
   $spouse_name = $_POST['spouse_name'];

   $sql1 = "INSERT INTO family_spouse (LAS_login_id, spouse_type, spouse_name)  VALUES ('$LAS_login_id', '".strtoupper($spouse_type)."','".strtoupper($spouse_name)."')";

this 2 code is working for insert into database and echo in the page. 这两个代码可用于插入数据库并在页面中回显。 How can I add delete button below echo "<td>" . $row['family_child_name'] . "</td>"; 如何在echo "<td>" . $row['family_child_name'] . "</td>";下面添加删除按钮echo "<td>" . $row['family_child_name'] . "</td>"; echo "<td>" . $row['family_child_name'] . "</td>"; for each row that I echo so user can delete the wrong row in the display table. 对于我回显的每一行,以便用户可以删除显示表中的错误行。

echo "<td>" . $row['family_child_name'] . " <a href='page.php&action=delete&id=family_name_id'>Delete</a></td>

然后在您的页面中获取(如果操作==删除)>执行查询以删除ID为家庭子名称表的ID的行。

$query = "SELECT * FROM family_child WHERE LAS_login_id = ($emp_id)";
$result = mysql_query($query) or die(mysql_error());
        echo "<table border='1'>
                <tr>
                    <th>Family Type</th>
                    <th>Name</th>
                    <th>Action</th>
                </tr>";     

    while($row = mysql_fetch_array($result))
    {
    echo "<tr>
    <td>" . $row['family_child_type'] . "</td>
    <td>" . $row['family_child_name'] . "</td>
    <td>
        <a href='../path/process.php?action=delete&id=".$row['family_child_id']."'>
        DELETE RECORD
        </a>    
    </td>
    </tr>";
    }
    echo "</table>";
    ?>

on process page check action = delete and write query for delete there family_child_id = ur primary key of table change according to ur table details 在进程页面上,检查操作=删除并写删除查询,family_child_id =根据您的表格详细信息更改表格的主键

EDIT 编辑

PROCESS PAGE: 处理页面:

if($_GET["action"] == "delete")
{
    $sql3="DELETE FROM family_child WHERE LAS_login_id =".$_GET["LAS_login_id"]; 
    $result3 = mysql_query($sql3);

    if (mysql_affected_rows() > 0) 
    {
        header("location:dashboard.php?tab=1");
    }
}

this coding working perfectly. 此编码工作完美。 i tried in my pc and posted this code here. 我在我的电脑上尝试过,并将此代码发布在这里。 it will insert the delete button automatically when u insert the new record. 当您插入新记录时,它将自动插入删除按钮。 and then if u click delete button it will delete the row details in mysql db.. 然后,如果您单击删除按钮,它将删除mysql db中的行详细信息。

 <body>
    <?
     echo "<tr>
            <td>";
               // your database connection
               // select database
                    $query = ("SELECT * FROM family_child");
                    $result = mysql_query($query) or die(mysql_error());
                    echo "<table border=1>
                            <tr>
                                <th>Family Type</th>
                                <th>Name</th>
                                <th>Delete Record</th>
                            </tr>";
                        while($row = mysql_fetch_array($result))
                        {
                        echo "<tr>";
                        echo "<td>" . $row['family_child_type'] . "</td>";
                        echo "<td>" . $row['family_child_name'] . "</td>";
                        echo "<td><form method=post>
                        <input name=id type=hidden value='".$row['family_child_name']."';>
                        <input type=submit name=submit value=Delete>
                        </form></td>";
                        echo "</tr>";
                        }
                    echo "</table>";

            echo "</td>           
        </tr>";

       // delete record
    if($_SERVER['REQUEST_METHOD'] == "POST")
    {
    if(isset($_POST['id']))
    {
    $id = mysql_real_escape_string($_POST['id']);
    $sql = mysql_query("DELETE FROM family_child WHERE family_child_name ='$id'");
    if(!$sql)
    {
        echo ("Could not delete rows" .mysql_error());
    }
    }
    }
    ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM