Javascript 如何在alertify确认删除中获取id
有人能教我如何获取一行数据的id,然后将其传递到delete.php中吗。我不知道怎么做,我对这个很陌生。。tnx很多Javascript 如何在alertify确认删除中获取id,javascript,php,html,mysql,alertify,Javascript,Php,Html,Mysql,Alertify,有人能教我如何获取一行数据的id,然后将其传递到delete.php中吗。我不知道怎么做,我对这个很陌生。。tnx很多 while($row = mysqli_fetch_assoc($result)) { echo $row['id']; echo " "; echo $row['name']; echo " "; echo "<
while($row = mysqli_fetch_assoc($result))
{
echo $row['id'];
echo " ";
echo $row['name'];
echo " ";
echo "<form id='form' action='delete.php'>";
echo "<input type='button' value='submit' id='btn".$row['id']."' name='but'>";
echo "<br>";
echo "
<script>
$('#btn".$row['id']."').click(function() {
alertify.confirm('Delete the selected entry?',function(e){
if(e) {
$('#form').submit();
return true;
} else {
return false;
}
});
});
</script>
";
}
while($row=mysqli\u fetch\u assoc($result))
{
echo$row['id'];
回声“;
echo$row['name'];
回声“;
回声“;
回声“;
回声“
”;
回声“
$('#btn.“$行['id'..”)。单击(函数(){
alertify.confirm('Delete the selected entry?'),函数(e){
如果(e){
$('表格').submit();
返回true;
}否则{
返回false;
}
});
});
";
}
echo”“;
echo“while($row=mysqli\u fetch\u assoc($result))
{
echo$row['id'];
回声“;
echo$row['name'];
回声“;
回声“;
回声“;
回声“;
回声“
”;
回声“
$('#btn.“$行['id'..”)。单击(函数(){
alertify.confirm('Delete the selected entry?'),函数(e){
如果(e){
$('表格').submit();
返回true;
}否则{
返回false;
}
});
});
";
}
在delete.php中
使用$\u POST[rowid]
获取要删除的行id的值。首先传播您的逻辑和html。我应该将其放在delete.php文件中吗?->$id=$POST['delete'];其中u wana获取id并使用IDI进行一些操作,而不仅仅是删除第一行,当我删除第二行、第三行或第四行时,它总是删除第一行
echo "<form id='form' action='delete.php'>";
echo "<input type='hidden' name='delete' value='' $row['id']."' >";
echo "<input type='button' class='btn_del' >";
echo "<br>";
now in js
<script>
$('.btn").click(function() {
alertify.confirm('Delete the selected entry?',function(e){
if(e) {
$('#form').submit();
return true;
} else {
return false;
}
});
});
</script>
then get value in delete.php by
$is=$_REQUEST['delete'];
// your query here
while($row = mysqli_fetch_assoc($result))
{
echo $row['id'];
echo " ";
echo $row['name'];
echo " ";
echo "<form id='form' action='delete.php'>";
echo "<input type='hidden' name='rowid' value='".$row['id']."' >";
echo "<input type='button' value='submit' id='btn".$row['id']."'>";
echo "</form><br>";
echo "
<script>
$('#btn".$row['id']."').click(function() {
alertify.confirm('Delete the selected entry?',function(e){
if(e) {
$('#form').submit();
return true;
} else {
return false;
}
});
});
</script>
";
}