I have what I am hoping is a pretty easy question. I'm kind of a newb at PHP, but have been coding in general for a short while now... Well, that's neither here nor there.
Anyways, I'm witing a php file that I need to have do 2 things (at least at this point). I have either of them working, but not the integration for them. Basically, I am writing a page to query a database, and return the "approved" valuse in a specific column of a table. I am able to have it do this, and spit out the correct values. I also need to have it loop through a directory on the server to get the paths and names of image files. I am able to get this to work as well. The problem really comes in when I try to compare the 2.
Here's the code I'm using:
Code: Select all
<?php
//header("Content-type: text/xml");
$dir = $_SERVER['DOCUMENT_ROOT']."/". "images/";
$handle=opendir($dir);
$counter = 0;
$link= @mysql_connect('localhost', 'root', 'password');
if(!$link) {
echo "<?xml version=\"1.0\"?>\n";
echo "<quotes>\n";
echo "<item>".mysql_error()."</item>\n";
echo "</quotes>\n";
exit();
}
mysql_select_db('tableName',$link);
if (!@mysql_select_db('tableName')) {
echo "<?xml version=\"1.0\"?>\n";
echo "<quotes>\n";
echo "<item>".mysql_error()."</item>\n";
echo "</quotes>\n";
exit();
}
$query = "SELECT * FROM art WHERE approve = 1 ORDER BY id DESC";
$results = mysql_query($query);
while ($file = readdir($handle))
{
//check file type for images
$the_type = strrchr($file, ".");
$is_picture = eregi("jpg|gif|bmp|png",$the_type); //adjust for other image types
if ($file != "." and $file != ".." and $is_picture)
{
$mypics[$counter] = $_SERVER['DOCUMENT_ROOT']."/". "images/fan/art/".$file;
$size[$counter] = getimagesize($mypics[$counter]);
$counter++;
}
}
closedir($handle);
while($line = mysql_fetch_assoc($results)) {
print $line["img"]; //I need to compare this with the $mypics array in the for loop, see if they are equal, and write the info to my XML doc.
}
print "<?xml version='1.0' encoding='UTF-8'?>\n";
print "<data>\n";
for ($i=0; $i < ($counter); $i++)
{
print "<node>\n";
print "<image_name>".$mypics[$i]."</image_name>\n"; //This is the array i need to compare.
print "<image_height>".$size[$i][0]."</image_height>\n";
print "<image_width>".$size[$i][1]."</image_width>\n";
print "</node>\n";
}
}
print "</data>\n";
?>Stpehen