[PHP + MYSQL] Deleting (unlink) multiple images.

Discussion in 'PHP' started by Miquexia, Dec 23, 2009.

  1. #1
    Hello,

    I'm looking for a solution to delete multiple images which has the SAME u_id in the database.

    So for example:

    Files: u_id
    123.jpg 100
    125.jpg 105
    158.jpg 100
    121.jpg 432

    I would like to remove 123.jpg and 158.jpg since they have the same u_id (100).

    So far I have:

    $sql_img="select * from `img_tbl` where `u_id`='$_SESSION[ses_tuid]'";
    $res_img=mysql_query($sql_img)or die(mysql_error());
    $row_img=mysql_fetch_array($res_img);
    $file_path="uploadimg/midthum_".$row_img[imgefile];
    unlink($file_path);
    $file_path="uploadimg/smallthum_".$row_img[imgefile];
    unlink($file_path);
    $file_path="uploadimg/thumb-".$row_img[imgefile];
    unlink($file_path);
    PHP:
    But all it does is remove only 1 image.

    But there are more images with the same u_id's.

    Can anyone help me out?

    Thanks
     
    Miquexia, Dec 23, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this
    $sql_img="select * from `img_tbl` where `u_id`='$_SESSION[ses_tuid]'";
    $res_img=mysql_query($sql_img)or die(mysql_error());
    while($row_img=mysql_fetch_array($res_img)) {
        $file_path="uploadimg/midthum_".$row_img[imgefile];
        unlink($file_path);
        $file_path="uploadimg/smallthum_".$row_img[imgefile];
        unlink($file_path);
        $file_path="uploadimg/thumb-".$row_img[imgefile];
        unlink($file_path);
    }
    PHP:
     
    JAY6390, Dec 23, 2009 IP
  3. Miquexia

    Miquexia Peon

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perfect! Thanks alot!!
     
    Miquexia, Dec 23, 2009 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no problem :)
     
    JAY6390, Dec 23, 2009 IP