RE: [PHP] Comparing Arrays - mysql_query & readdir
| From: | stephan dot schoell at chhos dot mail dot abb dot com | Date: | Mon, 03 Jul 2000 13:01:15 +0000 |
| Subject: | RE: [PHP] Comparing Arrays - mysql_query & readdir | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-4479@lists.php.net to get a copy of this message | ||
the foreach construct is new under PHP4! So probably if you work with PHP3
you'll have to replace it by list() and each() constructs (refer to the manual).
-Steff
|------------->
|(Embedded |
|image moved |
|to file: |
|pic14472.pcx)|
| |
|------------->
>------------------------------------------------------------------------|
|Emile Axelrad <mail@protonic.com> |
|03.07.2000 14:51 |
>------------------------------------------------------------------------|
To: Lawrence Blades <lrblades@clarksdale.com>, php-general@lists.php.net
cc: (bcc: Stephan Schoell/CHHOS/ABB)
Subject: RE: [PHP] Comparing Arrays - mysql_query & readdir
Security Level:? Internal
> I have a mysql table containing the file names of thumbnail images used
> in a catalog.
> I want to compare those filenames with the actual files stored in the
> web server directory.
>
> So I use a mysql_query to create an array of the filenames from the
> database, and opendir/readdir to create an array of the directory
> filenames.
>
> What I would like to do is compare the arrays and list the files that
> are in the directory, but not in the database (so I know which images
> can be deleted from the directory).
>
> Any help?
How does this general code sound [I'm no PHP expert though...] so you'll
need to mess it about yourself
foreach ($filenames as $currentfile) {
$result = mysql_query("SELECT * FROM filenames WHERE
filename='$currentfile'");
if ($rs = mysql_fetch_array($result)) {
# This file is in the directory and the database
} else {
# This file is in the directory but not the database
echo "Deleteable: " . $currentfile;
}
}
[Have I missed the point...?]
- Emile Axelrad
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net