Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created November 14, 2015 13:19
Show Gist options
  • Save dwihujianto/3f851ee631d0b01e64a4 to your computer and use it in GitHub Desktop.
Save dwihujianto/3f851ee631d0b01e64a4 to your computer and use it in GitHub Desktop.
Multifield update
<pre>
<form action="post.php" method="POST">
Kode <input type="text" name="_id[]">
Nama <input type="text" name="_nama[]">
Kode <input type="text" name="_id[]">
Nama <input type="text" name="_nama[]">
Kode <input type="text" name="_id[]">
Nama <input type="text" name="_nama[]">
<input type="submit" value="simpan">
</form>
</pre>
<?php
$id = $_POST['_id'];
$nama = $_POST['_nama'];
$data = array_combine($id, $nama);
$sql = null;
foreach ($data as $key => $value) {
$sql .="UPDATE table SET nama = ".$value." WHERE id = ".$key;
}
echo $sql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment