Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/114767-solved-folder-list-and-compare/
Share on other sites

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();
?>

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();
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.