Re: [Perchpole] Displaying an Image from Another Table
Hello,
I am trying to test out this code for another section where it would be useful. Anyway, I got the code working fine but sometimes when I enter a new listing, it will give me an error instead of displaying the data. Here is my test page so you can see the error:
http://www.charlotteparent.com/indextestapril.php
As you will see, Entry with Title 4 is not displaying.
Is there anything I am doing wrong or a way to fix this from happening once I add a new listing? Here is my test code:
<?php
require_once "C:/Inetpub/charlotteparent/cmsAdmin/lib/viewer_functions.php";
list($mp3Records,) = getRecords(array(
'tableName' => 'mp3',
'allowSearch' => true,
));
$albumNums = join(',', array_pluck($mp3Records, 'album'));
if ($albumNums) {
list($albumRecords,) = getRecords(array(
'tableName' => 'album',
'where' => "num IN ($albumNums)",
'allowSearch' => false,
));
$albumsByNum = array_combine(array_pluck($albumRecords, 'num'), $albumRecords);
}
else {
$albumsRecords = array();
$albumsByNum = array();
}
?>
<?php foreach ($mp3Records as $mp3): ?>
<?php $album = $albumsByNum[$mp3['album']] ?>
Title: <?php echo htmlspecialchars($mp3['title']) ?><br />
Album: <?php echo htmlspecialchars($album['albumname']) ?><br />
<?php foreach ($album['cover'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>
<?php endif ?>
<?php endforeach ?>
<hr />
<?php endforeach ?>
Thanks!
April