Membuat Edit Multiple Dengan PHP - Pada kesempatan yang lalu kita telah belajar membuat Delete Mulitple Dengan PHP, Maka pada kesempatan kali ini saya akan memberikan panduan untuk membuat Edit Multiple Dengan PHP. Sebagaimana telah kita ketahui bahwa pentingnya multiple pada setiap proses sehingga dapat memudahkan dan mempercepat dalam proses edit ataupun hapus data.
Langkah membuat edit multiple dengan PHP
- Buka aplikasi Xampp, kemudian aktifkan apache dan mysql
- Selanjutnya membuat database MySQL dengan nama "edit" dengan tipe field seperti pada gambar berikut ini.
- Buka juga Aplikasi Text Editor pada komputer anda, kemudian buatlah sebuah koneksi untuk menghubungkan antara database dan MySQL. silahkan bagi anda yang belum tahu cara membuat koneksi database dengan mysql klik disini.
- Setelah membuat koneksi, selanjutnya kita membuat halaman edit multiple seperti berikut ini.
- Untuk membuat halaman, gunakan script berikut ini.<style>
body {
font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
background: #E6EAE9;
align: center;
}
a {
color: #c75f3e;
}
#mytable {
width: 700px;
padding: 0;
margin: 0;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
th {
font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(bg_header.jpg) no-repeat;
}
th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
td.alt {
background: #F5FAFA;
color: #797268;
}
th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(bullet1.gif) no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}
th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(bullet2.gif) no-repeat;
font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
color: #797268;
}
button.mult_submit {
background-color: transparent;
border: 1px solid #336699;
border-radius: 36px 36px 36px 36px;
padding: 5px;
margin-top: 9px;
cursor:pointer;
}
img, input, select, button {
vertical-align: middle;
}
button {
display: inline;
}
.nowrap {
white-space: nowrap;
}
.icon {
margin-left: 0.3em;
margin-right: 0.3em;
vertical-align: -3px;
}
</style>
<form action="editmultiple.php" method="post">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("multiedit", $con);
$result = mysql_query("SELECT * FROM files");
echo '<table id="mytable" cellspacing="0" summary="The technical
specifications of the Apple PowerMac G5 series">
<tr>
<th scope="col" abbr="" class="nobg"> </th>
<th scope="col" abbr="Name" style="width: 159px;">Name</th>
<th scope="col" abbr="Email" style="width: 159px;">Email</th>
<th scope="col" abbr="Address" style="width: 259px;">Address</th>
</tr>
';
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<th scope='row' class='spec'>" . '<input name="selector[]" type="checkbox" value="'.$row['id'].'">' . "</th>";
echo "<td>" . $row['filename'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td style='overflow:hidden;'>" . $row['address'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<button class="mult_submit" title="Change" value="edit" name="submit_mult" type="submit">
<span class="nowrap">
<img class="icon" width="16" height="16" alt="Change" title="Change" src="b_edit.png">
Change
</span>
</button>
</form> - Buat juga script untuk menggunakan edit multiple<form action="editexec.php" method="post">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("multiedit", $con);
$edittable=$_POST['selector'];
$N = count($edittable);
for($i=0; $i < $N; $i++)
{
$result = mysql_query("SELECT * FROM files where id='$edittable[$i]'");
while($row = mysql_fetch_array($result))
{
echo '<div style="width: 266px; background-color:#DFDFDF; border:1px solid #D3DCE3; padding:5px; border-width: 0px 0px 1px; margin-bottom: 8px;">';
echo '<input name="bbbb[]" type="hidden" value="'.$row['id'].'" /><input name="textfield[]" type="text" value="'.$row['filename'].'" /><br>';
echo '<input name="email[]" type="text" value="'.$row['email'].'" /><br>';
echo '<textarea name="address[]" cols="30" rows="5">'.$row['address'].'</textarea><br>';
echo '</div>';
}
}
mysql_close($con);
?>
<input name="" type="submit" value="Edit">
</form> - Simpan file-file tadi pada satu folder.
- Selamat mencoba ...
Demikian panduan mengenai Membuat Edit Multiple Dengan PHP semoga bisa bermanfaat bagi anda dan bisa digunakan sebagaimana mestinya.
0 Comments