Re: [chris] Displaying an Image from Another Table
Hmmm, interesting, but got error like :
MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY dragSortOrder DESC' at line 3
Here is the exact definition of my 2 tables
TABLE "MP3"
title = mp3_titre
album = mp3_album
TABLE "ALBUMS"
title = album_name
cover (upload) = album_cover
and here is my code
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
$libraryPath = 'admin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/vhosts/oradio.fr/httpdocs/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
//list($mp3Records, $mp3MetaData) = getRecords(array(
//'tableName' => 'mp3',
//'leftJoin' => array('albums' => 'mp3_album'),
//));
list($mp3Records,) = getRecords(array(
'tableName' => 'mp3',
'allowSearch' => true,
));
$albumsNums = join(',', array_pluck($mp3Records, 'albums'));
list($albumsRecords,) = getRecords(array(
'tableName' => 'albums',
'where' => "num IN ($albumsNums)",
'allowSearch' => false,
));
$albumsByNum = array_combine(array_pluck($albumsRecords, 'num'), $albumsRecords);
?>
<head></head>
<body>
<?php foreach ($mp3Records as $mp3): ?>
<?php $album = $albumsByNum[$mp3['mp3_album']] ?>
Title: <?php echo htmlspecialchars($mp3['mp3_titre']) ?><br />
Album: <?php echo htmlspecialchars($album['album_name']) ?><br />
<?php foreach ($album['album_cover'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>
<?php endforeach; ?>
</body>