duanping2809 2009-06-03 17:15
浏览 17

使用原型js在php中删除操作

I am using php / mysql and protype.js to delete record from a table. problem is that after deleting record from grid, grid is not updating automatically in template.

This is my code:

Step 1: index.php

<?php
    require("Connection.php");
    $sql = "SELECT * from tbluser";
    $result=mysql_query($sql);
?>
<html>
<head>
    <script src="prototype.js" type="text/javascript"></script>
    <script src="scriptaculous-js/src/scriptaculous.js" type="text/javascript"></script>    
    <script language="javascript">
        function fnDeleteRecord(id)
        {
            new Ajax.Request('delete.php?action=Delete&id='+id,{method:'get'});
        }
    </script>
</head>
<body>
<table id="userrecords" border="1" cellpadding="0" cellspacing="0" width="700">
    <tr>
        <th> User Name </th>

        <th> Password </th>

        <th> Address </th>

        <th> Phone Number </th>

        <th> Action </th>
        <th> Status </th>
    </tr>
<?php

while($row = mysql_fetch_array($result))
{
    echo "<tr id='".$row[id]."'>";

    echo "<td>".$row['user_name']."</td>";

    echo "<td>".$row['pass']."</td>";

    echo "<td>".$row['address']."</td>";

    echo "<td>".$row['phone_no']."</td>";

    echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 /><a href='javascript:void(0);' onclick=fnDeleteRecord('".$row['id']."'); >Delete</a></td>";

    if($row['status'] == 'enabled')
        echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/enable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','disabled')  /></td>";
    else if ($row['status'] == 'disabled')
        echo "<td><img src='images/spinner.gif' id='a[$row[id]]' alt=icon border=0 style='display:none;' /><img src='images/disable.png' alt=icon border=0 onClick=fnUpdateStatus('".$row['id']."','enabled') /></td>";

    echo "</tr>";
}
    echo "</table>";

    mysql_close($con);

?>
</body>
</html>

Step 2: delete.php

<?php
require_once('connection.php');
if ($_GET['action'])
{
    switch($_GET['action'])
    {
        case 'Delete':
            $sql = "Delete from tbluser where id ='".$_GET['id']."'";
            $result = mysql_query($sql);
            if(!$result)
                echo "some problem occured during delete operation";
            break;
    }
}
?>
  • 写回答

1条回答 默认 最新

  • dongpu9481 2009-06-03 18:02
    关注

    You can remove that table row with prototype:

    <script language="javascript">
       function fnDeleteRecord(id)
       {
           new Ajax.Request('delete.php?action=Delete&id='+id,{method:'get'});
           $(id).remove(); // because <tr id='".$row[id]."'> :)
    
       }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统