unlink image + delete row dari tabel

alvin cipmunk · Nov 12, 2011
masbro,, saya ada per tanyaan neh...
saya mau menghapus dari tabel sp_image dengan paramater id_galeri sekaligus delete image dari folder dan tabel sp_galeri..
tapi dngan script saya malah perulangannya ga mau berhnti..
jadi lama banget ngeload halaman nya....
ini scriptnya sementara..:
<?php include("session.php"); ?>
<?php  
//file delete-gallery.php  
//koneksi ke database  
include ('../Connections/koneksi.php');  
if(isset($_GET['id'])){  
    $id = (int) $_GET['id'];  
    $sql = "select * from sp_image where id_galeri='$id'";  
    $result = mysql_query($sql);  
    if(mysql_num_rows($result) > 0 ){  
	
	while(mysql_num_rows($result) > 0 ){
        $data = mysql_fetch_array($result);  
        //delete file  
        @unlink('../images_galeri/'.$data['url']);  
		@unlink('../images_galeri/thumbs/thumb_'.$data['url']);
        //delete data di database  
        mysql_query("delete from sp_image where id_galeri='$id'"); 
		mysql_query("delete from sp_galeri where id_galeri='$id'"); 
	}
    }  
}   
header("Location: galeri.php");



mohon bantuanya... :D
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Nov 17, 2011 · 0 Suka · 0 Tidak Suka
0
Loading...
Ellyx Christian · Nov 18, 2011 · 0 Suka · 0 Tidak Suka
<?php
//file delete-gallery.php
//koneksi ke database
include ('../Connections/koneksi.php');
if(isset($_GET['id'])){
	$id = (int) $_GET['id'];
	$sql = "select * from sp_image where id_galeri='$id'";
	$result = mysql_query($sql);
	if(mysql_num_rows($result) > 0 ){
		$data = mysql_fetch_array($result);
		//delete file
		@unlink('../images_galeri/'.$data['url']);
		@unlink('../images_galeri/thumbs/thumb_'.$data['url']);
		//delete data di database
		mysql_query("delete from sp_image where id_galeri='$id'");
		mysql_query("delete from sp_galeri where id_galeri='$id'");
	}
}
header("Location: galeri.php");