dpdhnd3577 2015-01-28 09:20
浏览 58
已采纳

如何添加删除链接

I'm trying to add a delete link button below the 'action' column which deletes an entry when clicked. I've created the delete.php file but i've been unsuccessful in creating a url to link it. The code below outputs the data in the 'receipt' table from my database....is it possible? how do i do it??

<?Php
require "config.php";           

$page_name="currentout.php";  
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}


$eu = ($start - 0); 
$limit = 10;                                 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 

$nume = $dbo->query("select count(id) from receipt")->fetchColumn();


echo "<TABLE class='t1'>";
echo  "<tr><th>ID</th><th>Name</th><th>Pass</th><th>Amount</th><th>Action</th></tr>";


$query=" SELECT * FROM receipt  limit $eu, $limit ";


foreach ($dbo->query($query) as $row) {

@$m=$i%2;
@$i=$i+1;   
echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td></tr>";
}
echo "</table>";

if($nume > $limit ){ 
echo "<table align = 'center' width='50%'><tr><td  align='left' width='30%'>";

if($back >=0) { 
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
} 

echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        
$l=$l+1;
}


echo "</td><td  align='right' width='30%'>";

if($this1 < $nume) { 
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td></tr></table>";

} 
?>
  • 写回答

1条回答 默认 最新

  • dongweihuai5601 2015-01-28 09:26
    关注

    change your this line

    echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td></tr>";
    

    to

    echo "<tr class='r$m'><td>$row[id]</td><td>$row[name]</td><td>$row[phone_num]</td><td>$row[Amount]</td><td><a href='delete.php?id=$id'>delete</a></td></tr>";
    

    Create a new file delete.php

    <?php
    $sql = "DELETE FROM receipt  WHERE ID=  :ID";
    $stmt = $pdo->prepare($sql);
    $stmt->bindParam(':ID', $_GET['id'), PDO::PARAM_INT);  
    $stmt->execute();
    header('location: index.php');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了