Why does my PHP script doesn't work?

  • Thread starter Thread starter W!LL
  • Start date Start date
W

W!LL

Guest
I'm trying to write a script to be able to delete picture file not used in my shop.

I have 2 size of pictures..one is called the item number followed by -01_S.gif and another one called the item number followed by -01_L.gif

So I wrote that:
###################################################
<?php
$resource = mysql_connect(localhost, XXXXXXX, XXXXXXX);
$db = mysql_select_db(XXXXXXXX, $resource)
or die ("Couldn't select database.");
$db;
// open the current directory by opendir
$handle=opendir(".");

while (($file = readdir($handle))!==false) {
$compteS = 0;
$compteL = 0;
$sqqql="SELECT * FROM products";
$answer = mysql_query($sqqql);
while ($answer_data = mysql_fetch_array($answer) )
{

$model = $answer_data['products_model'];
$imageS = "$model-01_S.gif";
$imageL = "$model-01_L.gif";


if ($file!=$imageS)
echo"";
else
$compteS=$compteS+1;

if ($file!=$imageL)
echo"";
else
$compteL=$compteL+1;

}

if ($compteS==0)
echo"File $file should be deleted.<br>";
if ($compteL==0)
echo"File $file should be deleted.<br>";
}
closedir($handle);
mysql_close($resource2);
echo"finish";
?>
#########################################
But when I run it, I get all file listed even if they are in my database... does anyone could suggest somehing?

Thank's
 
I didnt read your code supppper carefully, but I dont see where you instantiate

where you have while (($file = readdir($handle))!==false) {,

change it to: while (($file = readdir($handle))!=false) {, note, i got rid of one of the = signs

that could be it..
 
Back
Top