Im abit lost as to how I can remove the images in this system
3 table ..
maincat = table 1
subcat = table 2
images = table 3
subcat table holds field maincat_id
images table holds subcat_id
used to cross reference them
Now I cant thinkup a way to unlink all the images related to the maincat_id
Here is code what I have so far:
Code: Select all
case 'delete_maincat':
if (array_key_exists("confirm",$_REQUEST)) {
echo '<br />Sub category & images were successfully deleted<br /><br /><br />Please wait while you are redirected ...
<meta http-equiv="refresh" content="3; url='.$_GET['referer'].'">';
$sql = mysql_query("SELECT photo_filename FROM gallery_images WHERE subcat_id='".$_GET['subcat_id']."'");
while ($row = @mysql_fetch_array($sql)) {
unlink($images_dir . '/' . $row[0]);
unlink($images_dir . '/tb_' . $row[0]);
}
$sql = mysql_query("DELETE FROM gallery_maincat WHERE maincat_id='".$_GET['maincat_id']."'");
$sql = mysql_query("DELETE FROM gallery_subcat WHERE maincat_id='".$_GET['maincat_id']."'");
}else{
echo 'Do you really want to delete this category and all its images?';
echo '<br /><br /><a href="index.php?action=process&process=delete_subcat&subcat_id='.$_GET['subcat_id'].'&confirm=y">Yes</a> - <a href="#" onClick="history.go(-1)">No</a>';
}
break;Code: Select all
$sql = mysql_query("SELECT photo_filename FROM gallery_images WHERE subcat_id='".$_GET['subcat_id']."'");
while ($row = @mysql_fetch_array($sql)) {
unlink($images_dir . '/' . $row[0]);
unlink($images_dir . '/tb_' . $row[0]);
}Maybe a table join is in order?
Thanks