Re: leftJoin (with images and multiple "joins" and multi-selects)
2 posts by 2 authors in: Forums > CMS Builder
Last Post: April 3, 2023 (RSS)
By kitsguru - April 1, 2023
In response to: https://www.interactivetools.com/forum/forum-posts.php?postNum=2238306#post2238306
<?php foreach ($blogRecords as $record): ?>
<h1><?php echo htmlencode($record['title']) ?></h1>
<?php foreach ($record['upload'] as $index => $upload): ?>
<img src="<?php echo $SETTINGS['uploadUrl'] ?>/<?php echo htmlencode($upload['urlPath']) ?>" alt="<?php echo htmlencode($record['title']) ?>" class="width"/>
<?php endforeach ?>
<?php endforeach ?>
This code only works if the "General Setting-> Upload Folder URL" is relative to the root such as 'cmsb/uploads' as $SETTINGS['uploadUrl'] is imcomplete. While you can enter 'uploads' and the preview shows the path relative to the root. Also it will not work with a custom directory.
I am trying to figure out the proper way to reference the true and complete path. Any help is appreciated.
By Dave - April 3, 2023
Hi Jeff,
If you use any of the code generator functions (getRecords,etc) it should do it automatically.
But if you're using custom code and getting the data right from the database you can use one of our internal functions from /lib/upload_functions.php
// Returns the absolute uploadDir and uploadUrl for a specific upload field. This is determined by: The dir/url of the CMS,
// .. the (potentially relative) upload dir/url in settings, and the (potentially defined) custom upload dir/url for the field.
// Usage: list($uploadDir, $uploadUrl) = getUploadDirAndUrl($fieldSchema);
function getUploadDirAndUrl($fieldSchema, $settingsUploadDir = null, $settingsUploadUrl = null, $returnOnErrors = false) {
So you might have something like this:
<?php
$tablename = "blog";
$fieldname = "uploads";
$schema = loadSchema($tablename);
$fieldSchema = $schema[$fieldname];
list($uploadDir, $uploadUrl) = getUploadDirAndUrl($fieldSchema);
?>
If you have that above your foreach block you can output the uploadUrl before each image. And I think you'll need to output just the filename for the upload. You may need to try a few variations of the code, but hopefully that will point you in the right direction.
interactivetools.com