<?php
$tbl_name="gallery";
$sql="SELECT * FROM `$tbl_name` ORDER BY title ASC";
$result=mysql_query($sql);
$count = mysql_num_rows($result);
?>
<form name="form1" method="post" action="">
<table width="598" border="1" bordercolor="#e5e5e5" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Title</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Image Article</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Image</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['title']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['content']; ?></td>
<td bgcolor="#FFFFFF"><img class="imgsmall" src="<?php echo "".$rows['image']."" ?>"/></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if(isset($_POST['delete'])) {
// Set arrays
$id_list = array();
$cat_list = array();
// Add checked items to $id_list Array
for($i=0;$i<$count;$i++){
$del_id = $_POST['checkbox'][$i];
if($del_id != NULL){
$id_list[] = $del_id;
}
}
// Build SQL WHERE IN $id_sql
$id_sql = "";
$a = "0";
foreach ($id_list as $value) {
if($a>0) $id_sql .= ",";
$id_sql .= $value;
$a++;
}
// Get Category Names
$sqla="SELECT image FROM `gallery` WHERE id IN ($id_sql)";
$resulta = mysql_query($sqla);
// Add Category Names to $cat_list Array
while($rslt = mysql_fetch_array($resulta)){
$cat_list[] = $rslt['category'];
}
// Build SQL WHERE IN $cat_sql
$cat_sql = "";
$a = "0";
foreach ($cat_list as $value) {
if($a>0) $cat_sql .= ",";
$cat_sql .= "'".$value."'";
$a++;
}
// Delete the records
$sql = "SELECT image FROM gallery WHERE image IN ($cat_sql)";
$result = mysql_query($sql);
unlink("gallery/".$cat_sql."");
$sql1 = "DELETE FROM gallery WHERE image IN ($cat_sql)";
$result1 = mysql_query($sql1);
}
?>
</table>
</form>
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE