2016-10-27 14 views
-1

誰かが一行のデータのIDを取得してdelete.phpに渡す方法を教えてください。私はこれを行う方法を知らない、私は非常にこれに新しい.. tnxたくさん。 delete.phpで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

shoul私はこれをdelete.phpファイルに入れますか? - > $ id = $ POST _ ['delete']; –

+0

あなたはidを取得してid –

+0

で何らかの操作をするだけで、最初の行が削除されます.2行目または3行目または4行目を削除すると、常に最初の行が削除されます –

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

使用$_POST[rowid]は、行IDの値が削除さを取得します。

関連する問題