douchun6221 2015-12-02 07:13
浏览 51
已采纳

从循环显示的视图列表中删除数据库行

I have a view list that displayed through php

$quedchan=pg_query("SELECT agent.agentname,  agent.onlinename, agent.channel, agentgroup.leadername FROM Agent LEFT JOIN agentgroup on agent.agentid=agentgroup.agentid where agent.channel like '%$DCH%'order by agent.channel");
    echo "<td class=\"form1\" align=\"center\" > Number </td>";
    echo "<td class=\"form1\" align=\"center\" > Agent Name </td>";
    echo "<td class=\"form1\" align=\"center\"> Agent Online Name </td>";
    echo "<td class=\"form1\" align=\"center\"> Agent Channel </td>";
    echo "<td class=\"form1\" align=\"center\"> Agent Group </td>";
    echo "<td class=\"form1\" align=\"center\">  </td>";

$counttttt=1;
    While($row3=pg_fetch_array($quedchan))
echo "<tr>";
        echo "<td class=\"forma\" align=\"center\"> ".$counttttt++." </td>";
        echo "<td class=\"forma\"name=\"dement\" align=\"left\"style=\"padding-left:10%;\"> ".$row3['agentname']." </td>";
        echo "<td class=\"forma\" align=\"left\"style=\"padding-left:8%;\"> ".$row3['onlinename']." </td>";
        echo "<td class=\"forma\" align=\"left\"style=\"padding-left:8%;\"> ".$row3['channel']." </td>";
        echo "<td class=\"forma\"align=\"left\"style=\"padding-left:6%;\"> ".$row3['leadername']." </td>";
        echo "<td class=\"forma\" align=\"center\"><img src=\"image\\delete.png\" width=\"20px\" height=\"20px\" style=\"padding-left:22%;cursor:pointer;\"/></td>
        </tr>";     

And I want to make a delete function, so that the delete image of a row can delete its row. I made this by give a name for agentname row, name=\"dement\". in order to catch the value I want to delete. Im using php in another page called delete.php :

<?php 
session_start();
include 'connect.php';

$dagname=$_GET['dement'];
$queda="DELETE FROM Agent where agentname='$dagname'";
$result=pg_query($queda);


if($result)
{   
    $_SESSION['delMessage11']='Selected Agent is successfully deleted!';
    header('Location: Dagent.php');
}
else
{
    echo "ERROR!"; 
}

?>

It doesnt work. I tried to use a reference from http://www.phpeasystep.com/mysql/7.html. it says I can get value of id (which I replace with agentname now) that sent from address bar. I implement it and become this

echo "<td class=\"form2\" align=\"center\"><a href=\"delete.php?agentname=<?    echo ".$row3['agentname'].";?>\">\"<img src=\"image\\delete.png\" onclick=\"dela();\" width=\"20px\" height=\"20px\" style=\"padding-left:22%;cursor:pointer;\"/></a></td>
                    </tr>";

But it doesnt work. Any help? Thank you

  • 写回答

1条回答 默认 最新

  • duandang2123 2015-12-18 02:37
    关注

    Why don't you use method ="get"? it's more simple. So when the button was clicked, 'something' (based on you need) would be save in a variable and directly move on into a new page which is filled by delete queries and use $_GET for catch the variable(filled by 'something') for support the queries and the attributes. when you are moving on into a new page then you will see the link, it would be like this

    DATA_NAME.php?$something.
    

    I Hope this can help you. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看