2016-10-27 64 views
-1

任何人都可以教我如何獲得一行數據的id然後傳遞到delete.php。我不知道如何做到這一點,即時通訊非常新的.. tnx很多。如何在alertify中得到id確認刪除

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> 
    "; 
} 
+0

首先傳播你的邏輯和html。 – mcklayin

回答

1
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 
+0

我把這個delete.php文件? - > $ id = $ POST _ ['delete']; –

+0

其中u wana得到id並進行一些操作,編號爲 –

+0

它只是刪除第一行,當我刪除第二或第三或第四行時,它總是刪除第一行 –

0
while($row = mysqli_fetch_assoc($result)) 
{ 

    echo $row['id']; 
    echo "&nbsp;&nbsp;&nbsp;"; 
    echo $row['name']; 
    echo "&nbsp;&nbsp;&nbsp;"; 
    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> 
    "; 
    } 

在delete.php 使用$_POST[rowid]讓行id的值被刪除。