Displaying an Image from Another Table
3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 26, 2010 (RSS)
Hi,
Below is the code I have used for a detail page about degree 'programs'. It works well and allows me to use fields from the 'schools' table.
When I want to show fields from the schools table I use code like this:
I have a problem when I try to get an uploaded image from the schools table to show up. However, if I upload the image to the programs table I can show the image using this code:
Why can't I get the image from the schools table using the same code as above (putting the 'schools.' in front of the field? In other words, the following code returns and error:
Please let me know if there is a work around (or if I am doing something wrong). I would rather upload the school picture once in the schools table instead of potentially multiple times (sometimes 3 or 4 times) in the programs table.
Thanks.
Below is the code I have used for a detail page about degree 'programs'. It works well and allows me to use fields from the 'schools' table.
$urlNum = getNumberFromEndOfUrl();
list($programsRecords, $programsMetaData) = getRecords(array(
'tableName' => 'programs',
'limit' => '1',
'leftJoin' => array('schools' => 'schoolNum'),
'where' => "programs.num = $urlNum"
));
$programsRecord = @$programsRecords[0]; // get first record
// show error message if no matching record is found
if (!$programsRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}
?>
When I want to show fields from the schools table I use code like this:
<? echo $programsRecord['schools.school_name'] ?>
I have a problem when I try to get an uploaded image from the schools table to show up. However, if I upload the image to the programs table I can show the image using this code:
<? foreach ($programsRecord['school_picture'] as $upload): ?>
<img src="<? echo $upload['thumbUrlPath'] ?>" />
<? endforeach ?>
Why can't I get the image from the schools table using the same code as above (putting the 'schools.' in front of the field? In other words, the following code returns and error:
<? foreach ($programsRecord['schools.school_picture'] as $upload): ?>
<img src="<? echo $upload['thumbUrlPath'] ?>" />
<? endforeach ?>
Please let me know if there is a work around (or if I am doing something wrong). I would rather upload the school picture once in the schools table instead of potentially multiple times (sometimes 3 or 4 times) in the programs table.
Thanks.
Re: [onlinemba] Displaying an Image from Another Table
By Chris - January 25, 2010
Hi onlinemba,
There's no automatic way to get uploads from a leftJoined table. You could try a getRecords on the uploads table directly.
There's no automatic way to get uploads from a leftJoined table. You could try a getRecords on the uploads table directly.
All the best,
Chris
Chris
Re: [chris] Displaying an Image from Another Table
That worked. Thanks.