After reading the article I tried to delete the image from the directory:

$getfile = mysql_query("SELECT I.filename FROM timages I LEFT JOIN tholidaysimages AS TH ON TH.imageid=I.id WHERE hotelid=".$hotelid); while ($row = mysql_fetch_object($getfile)) { $file = $row->pic; unlink("../../static/uploads/holidays/$file"); 

At the entrance of the function I only have $ hotelid. What am I doing wrong?

  • one
    In your request, the field is called filename , why do you refer to it below as pic ? And LEFT in JOIN absolutely not appropriate, you do not need to receive records from pictures, regardless of whether there are entries for them in the second table or not - Mike
  • And the hotelid field is in which table? - Akina
  • There was no result, the hotelid in the tholidaysimages table in SQL this query is correct, unloads the file names with the extension completely. Perhaps the problem is that the function file is in admin / modules, and the directory in static / uploads / holidays, i.e. you need to rise to a higher level, and then go into static / ....... - Den
  • If you know abs. ways, why use relative? and how the user from whom works pkhp, with the rights in file system? By the way, what symptoms made you ask ? What am I doing wrong? - Akina

1 answer 1

Akina and Mike thanks for the help. The final working option, who will benefit from:

 $getfile = mysql_query("SELECT I.filename FROM timages I LEFT JOIN tholidaysimages AS TH ON TH.imageid=I.id WHERE hotelid=".$hotelid); while ($row = mysql_fetch_array($getfile)) { $file = $row["filename"]; unlink("../static/uploads/holidays/".$file); } mysql_query("UPDATE tholidays set status=0 where id=".$hotelid); mysql_query("DELETE FROM timages WHERE timages.id IN ( SELECT tholidaysimages.imageid FROM tholidaysimages WHERE tholidaysimages.hotelid = $hotelid)");