didgydont Posted July 15, 2008 Share Posted July 15, 2008 hi all i have managed to list all jpg files in a folder but want it to check a sql data base and see if file is used i have came close this code below marks 1 file as used <?php include("connect.php"); $result = mysql_query("SELECT * FROM stock"); while($row = mysql_fetch_array($result)) { $image = $row['image']; } //############ folder list###################3 echo "Pictures On Server..<br>"; $folderc = "Images"; $dir=dir("./$folderc/."); while($filename=$dir->read()) {if(eregi("^[_a-z0-9-]+.jpg$", $filename)){ if ($filename==$image){echo "$filename in use</br>";} else {echo "$filename </br>";} } } $dir->close(); ?> but this code below list all the right files but repeats it self as many times as pictures <?php include("connect.php"); $result = mysql_query("SELECT * FROM stock"); while($row = mysql_fetch_array($result)) { $image = $row['image']; //############ folder list###################3 echo "Pictures On Server..<br>"; $folderc = "Images"; $dir=dir("./$folderc/."); while($filename=$dir->read()) {if(eregi("^[_a-z0-9-]+.jpg$", $filename)){ if ($filename==$image){echo "$filename in use</br>";} else {echo "$filename </br>";} } } } $dir->close(); ?> thank you for your time Quote Link to comment https://forums.phpfreaks.com/topic/114767-solved-folder-list-and-compare/ Share on other sites More sharing options...
sader Posted July 15, 2008 Share Posted July 15, 2008 Not sure but how about this <?php //############ folder list###################3 echo "Pictures On Server..<br>"; $folderc = "Images"; $dir=dir("./$folderc/."); while($filename=$dir->read()) { if(eregi("^[_a-z0-9-]+.jpg$", $filename)) { //now try find this filename in database $result = mysql_query("SELECT * FROM stock WHERE image='$filename' LIMIT 1"); //was there any results returned by query if(mysql_num_rows(result)>0)echo "Image in use<br />"; else echo "Image unused<br />"; } } $dir->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114767-solved-folder-list-and-compare/#findComment-590122 Share on other sites More sharing options...
didgydont Posted July 15, 2008 Author Share Posted July 15, 2008 this is what i did <?php include("connect.php"); /////////////////////////////////// $result = mysql_query("SELECT * FROM stock"); while($row = mysql_fetch_array($result)) { $image = $row['image']; } //############ folder list###################3 echo "Pictures On Server..<br>"; $folderc = "Images"; $dir=dir("./$folderc/."); while($filename=$dir->read()) {if(eregi("^[_a-z0-9-]+.jpg$", $filename)){ $sql3 = "select * from stock where image='$filename'"; $result3 = mysql_query($sql3); if (mysql_num_rows($result3)== 1) {echo "$filename in use</br>";} else {echo "$filename </br>";} } } $dir->close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114767-solved-folder-list-and-compare/#findComment-590123 Share on other sites More sharing options...
didgydont Posted July 15, 2008 Author Share Posted July 15, 2008 Not sure but how about this <?php //############ folder list###################3 echo "Pictures On Server..<br>"; $folderc = "Images"; $dir=dir("./$folderc/."); while($filename=$dir->read()) { if(eregi("^[_a-z0-9-]+.jpg$", $filename)) { //now try find this filename in database $result = mysql_query("SELECT * FROM stock WHERE image='$filename' LIMIT 1"); //was there any results returned by query if(mysql_num_rows(result)>0)echo "Image in use<br />"; else echo "Image unused<br />"; } } ?> thank your for your help i will try that too just for learing Quote Link to comment https://forums.phpfreaks.com/topic/114767-solved-folder-list-and-compare/#findComment-590126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.