I have what I thought was a straight-forward query, but I cant seem to get it to work. All help appreciated!
The Tables:
There are two tables involved: gallery_meta and prm_album. The gallery_meta tbl contains the data for images stored in the file structure. The prm_album tbl simply aligns album ID’s with album regular-text Names. For both tbls, the field names used in the query are correct.
The Query:
In the code below, I first get an array of saved album names. I then check the file structure to see which directories actually contain images. At this point I want to query the db again for a thumbnail for each of the albums that return as positives. It is here that the the process fails.
All I get is a whitescreen, no error reporting whatsoever. The array $albums is being filled successfully, and the $id variable is being passed to the $q query. $pattern is simply the file path to the parent directory where the album directories are stored.
//Get album names from db
$albums = array();
$q="SELECT ID, Name FROM prm_album WHERE 1";
$sql=mysql_query($q) or die(mysql_error());
while($r=mysql_fetch_array($sql)) {
$album = $r['Name'];
$album_dir = $pattern.$album.'/';
//check which albums actually contain images (dividing to account for thumbs, med, lrg.)
$filecount = count(glob($album_dir.'*'))/3;
//if images found, put album in array
if($filecount >= 1) {
$albums[ $r['ID'] ] = $filecount;
}
}
foreach($albums as $id => $filecount) {
$q="SELECT m.AlbumID, m.FileName, m.FileExt,
m.LegacyName, m.IsDefault,
p.Name
FROM gallery_meta AS m
LEFT JOIN prm_album AS p
ON m.AlbumID = p.ID
WHERE m.AlbumID = $id
AND Public = 1
ORDER BY IsDefault DESC
LIMIT 0,1";
$sql=mysql_query($q) or die(mysql_error());
while($r=mysql_fetch_array($sql)) {
$album=$r['Name'].'/';
$legacyname=$r['LegacyName'];
$filename=$r['FileName'].'-sm.';
$ext=$r['FileExt'];
echo '<img src="'$pattern.$album.$filename.$ext.'" />'.$legacyname.'<br/>';
}
}
Change
to
The first dot was missing. And always set these lines on top of your script =)