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条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch