dpwbc42604 2013-06-16 16:30
浏览 43
已采纳

需要将“删除”按钮定位到PHP中的while循环中的元素

I have the following loop, which creates a list from a database:

for ($i=0;$i<count($tutor_subj);$i++){
$query_tutors = "SELECT level, subject FROM level, subject WHERE level.id = '$tutor_lvl[$i]' AND subject.id = '$tutor_subj[$i]'";       
$result_t = mysqli_query($db_conx, $query_tutors);
    while($m = mysqli_fetch_array($result_t)){
    echo $m['level']." ".$m['subject']." ".$tutor_top[$i]."<div style='float:right; padding-right:5px;'><a href='#'><img src='images/remove_btn.png' onclick='removeSubj'></a></div></br>";
        }
    }
?>

As you can see I'm adding a 'remove' button in the html after each entry, and I want to use this button to allow the users to delete that particular row of data from the database if they choose.

My question is how can I link the row from this while loop to the button being generated at the end of each line (so that the appropriate entry is deleted in the DB)?

PS - I havent written the javascript/jquery function removeSubj yet because I'm stuck, hence am not including that

  • 写回答

2条回答 默认 最新

  • dswqw66280 2013-06-16 16:40
    关注

    Add an unique identifier to onclick='removeSubj' so that when it is called, you can determine what you would want to delete. You could use something like onclick='removeSubj("unique_identifier")'. Replace that unique_identifier with something that is always unique for every row in your database (for example an id-field).

    You can then use this value in your javascript function, and finally in your server-side script, to delete the correct row.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法