Showing results based on a single record, info1 in images
2 posts by 2 authors in: Forums > CMS Builder
Last Post: August 8, 2013 (RSS)
By crazyfish - August 7, 2013
Greetings,
I have a photographer who has 5 galleries. Each has one record with multiple images. I need to have a "search function" or URL or whatever - If she tags info2 as Rwanda or rwanda, how can I search that field and show the results?
So far I set up a new page that checks all 5 galleries ( probably an easier way, but we'll skip that for now ) and show results? I can't seem to find a function that is appropriate. There will never really be a search function, just a link. In the future we may only add one or two other info2 "locations"
Tried this type of approach without success - I'm thinking its a multi-record function results.php?info2=rwanda
Just testing with one gallery - "people" so you can see my thought process for the results
<?php foreach ($peopleRecords as $record): ?>
<?php foreach ($peopleRecord['images'] as $index => $upload): ?>
<div class="block"> <a href="<?php echo $upload['urlPath'] ?>" rel="prettyPhoto[gallery1]"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /></a><br/>
<br/>
</div>
<?php endforeach ?>
<?php endforeach ?>
Thanks, always appreciate your help,
By gregThomas - August 8, 2013
Hi Crazyfish,
If you only want to return image results the easiest method would be to use a mysql_select function to search the uploads table directly, and only let it return images from the 5 galleries, something like this would work:
<?php
$images = mysql_select('uploads', "`tableName` IN ('{$peopleRecords['_tableName']}') AND `fieldName` = 'images' AND `info2` LIKE '%Rwanda%'");
?>
<?php foreach($images as $upload): ?>
<div class="block">
<a href="<?php echo $SETTINGS['uploadUrl'].$upload['urlPath'] ?>" rel="prettyPhoto[gallery1]">
<img src="<?php echo $SETTINGS['uploadUrl'].$upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
</a>
<br/>
<br/>
</div>
<?php endforeach; ?>
This is just example code, so you might have to make a few changes to get it working.
So the mysql_select function just searches the uploads table, and returns the results in an array. I've added a MySQL statement that will only return results from the people section (although I've used an IN statement, if you want to search other sections at the same time, add the tablenames in comma seperated strings inside the brackets).
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com