Jump to content

multiple delete with checkbox and php+MySQL


spirit_in_blue

Recommended Posts

Hallo all,

 

I'm new here. And I'm newbie too in php programming. I just wish that this forum could help me a lot on php matters.

 

Could anyone have a full php script for deleting records that shown, with a checkbox in every line shown.

 

I've tried to search for the script from google, but i can't find any.

 

Thank you before.

ok have a load of checkboxes ALL called 'chkbx[]' and set their value to the record id.

 

(you can call em what you like but the [] are essential. - maybe del[] would be better)

 

so when you submit the form with all these check boxes you will create an array called del...

 

here is the php/mysql that will delete all those rows...

 

<?php
$delarr = implode(',',$_POST['del']);

$qry = "DELETE FROM `atable` WHERE `record_id` IN (" . $delaar . ")";
$qry = mysql_query($qry);

?>

 

dead easy!!!!!

 

 

I have my script like this :

===============================================================================

 

<?

include 'includes/library.php';

check_login();

$noabjad = $_SESSION['no_abjad'];

connectdb();

$cari=mysql_query("select * from login where no_abjad='".$noabjad."'");

$isi = mysql_fetch_row($cari);

$group_id=$isi[7];

$access_id=$isi[4];

 

$jml=10;

$start=$_GET['start'];

if(empty($start))

{ // This variable is set to zero for the first page

$start = 0;

}

$last=$start+$jml;

 

$select=$_POST['select'];

$nama=$_POST['input'];

if (empty($select))

{$select=$_GET['select'];

if (empty($nama))

{$nama=$_GET['nama'];}

}

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>User Search</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

<div align="center"><strong><font color="#0000FF" size="6">Data Dokumen</font></strong>

</div>

 

 

 

<form>

  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="4">

    <tr bgcolor="#9999FF">

      <td width="282" bgcolor="#9999FF">

      <div align="center"><em>Pilihan</em></div></td>

  <td width="282">

      <div align="center"><strong>No Agenda</strong></div></td>

  <td width="302">

      <div align="center"><strong>Tgl Terima</strong></div></td>

      <td width="282">

      <div align="center"><strong>No Dokumen</strong></div></td>

  <td width="282">

      <div align="center"><strong>Tgl Dokumen</strong></div></td>

      <td width="282">

      <div align="center"><strong>Jenis Dokumen</strong></div></td>

      <td width="282">

      <div align="center"><strong>Perihal</strong></div></td>

      <td width="282">

      <div align="center"><strong>Dari</strong></div></td>

      <td width="282">

      <div align="center"><strong>Odner</strong></div></td>

  <td width="282">

      <div align="center"><strong>File</strong></div></td>

  <td width="282">

    <div align='center'><strong>Edit</strong></div></td>

<td width='282'>

      <div align='center'><strong>Hapus</strong></div></td>

<?

 

 

//-----------Administrator View----------

 

//cari access dan kode bagian

if ($access_id==1)

{echo "

<td width='282'>

        <div align='center'><strong>Kode Bagian</strong></div></td>

";

}

// --closed--

 

?>

</tr>

<?

$query2 = "SELECT * FROM data  where $select LIKE '%".$nama."%' order by no_agenda";

$result2 = mysql_query("SELECT * FROM data where $select LIKE '%".$nama."%' order by no_agenda");

echo mysql_error();

$total = mysql_num_rows($result2);

 

$resultx = mysql_query("SELECT * FROM data  where $select LIKE '%".$nama."%' limit $start,$jml");

 

if (($last<=$total) or ($resultx))

{

$query ="SELECT * FROM data where $select LIKE '%".$nama."%' limit $start,$jml";

$result = mysql_query("SELECT * FROM data where $select LIKE '%".$nama."%' limit $start,$jml");

 

$x = mysql_num_rows($result);

for ($i=0;$i<$x;$i++)

{

echo "<tr bgcolor=";

 

if (($i%2)==1)

{echo "'#EAEAFF'";}

else

{echo"'#FFFFFF'";}

 

echo "><td>";

$row = mysql_fetch_row($result);

?>

<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row[0]; ?>"><br>

<?

echo "</td>";

echo "<td>";

echo "<b>".$row[1]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[2]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[3]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[4]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[5]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[6]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[7]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".$row[8]."</b>"."<br>";

echo "</td>";

echo "<td>";

echo "<b>".'<p align="center"><a href="images/files/'.$row[14].'" target="_blank">Open</p>'."</b>";

echo "</td>";

echo "<td>";

echo '<div align="center"><a href="input_edit.php?no='.$row[0].'">Edit</a></div>';

echo "</td>";

echo "<td>";

echo '<div align="center"><a href="input_delete.php?no='.$row[0].'">Delete</a></div>';

echo "</td>";

if ($access_id==1)

{

echo "<td>";

echo "$group_id";

echo "</td>";

}

echo "</tr>";

}

//mysql_free_result($result);

//mysql_close();

}

 

 

?>

  </table>

 

<!--- <td align="center" ><table width="100%" border="0">

      <tr>

        <td align="center"><p>

            <INPUT TYPE="button" VALUE="Previous Page" onClick= "self.location='input_search.php'">

          </p>

        </td>

      </tr>

    </table>

!--->

<table width="100%" border="0" cellpadding="0" cellspacing="4">

    <tr bgcolor="#9999FF">

      <td>Hapus Pilihan</td>

    </tr>

  </table>

</form>

 

<table align="center">

  <tr>

    <td rowspan="2">

<form method="post" action="input_search_proses.php">

<?

echo "<p align='center'>";

$hal=$_GET['hal'];

if (empty($hal))

{

$hal=1;

}

else

{

$hal=$_GET['hal'];

}

echo "Halaman ke : ".$hal."<br>

Page :    ";

 

$hasil=$total/$jml;

for ($z=0;$z<$hasil;$z++)

{

$a=$z+1;

echo "<a href='input_search_proses.php?start=".$b."&select=".$select."&nama=".$nama."&hal=".$a."'>".$a."</a>";

echo "   ";

$b=$b+$jml;

}

 

?>

</form>

 

</td>

    <td width="61"><input name="button" type="button" onClick= "self.location='input_search.php'" value="Pencarian Ulang"></td>

  </tr>

  <tr>

    <td height="21"> </td>

  </tr>

</table>

 

 

</body>

</html>

 

==============================================================================

 

do you have any solution?

 

Thank you

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.