How to deal with displaying several result generated with "WHERE" condition

13 posts by 4 authors in: Forums > CMS Builder
Last Post: January 27, 2010   (RSS)

My question is simple.
I have an editor lets say Poster

Poster have 3 fields
- Title
- Theme (list with 3 choice theme1, theme2, theme3)
- Photo (upload field with only 1 upload possible)

I want to make a page where all group of thumbs for the same "theme" will be displayed.
So on this page i will have in my case 3 group of thumbs

I'd like to have that kind of display

- Theme (display only 1 time)
- Thumb
-Thumb
-Thumb
-Thumb... etc (thumbs should be display in a table with that kind of function that already work perfectly for me

<?php $maxCols=4; if (@++$count % $maxCols == 0): ?>

I know how to do that with one condition, but have no idea to do it with several

here is what i do for one condtion:

<?php

require_once "/var/www/vhosts/atoutspubonline.com/httpdocs/admin/lib/viewer_functions.php";

list($posterRecords, $posterMetaData) = getRecords(array(
'tableName' => 'poster',
'allowSearch' => '0',
'where' => 'theme = "theme1"',
));

?>

Re: [willbegood] How to deal with displaying several result generated with "WHERE" condition

By ross - March 30, 2009

Hi there.

Just to make sure I am on the right track here, it sounds like what you need is to have all your images appear but group them based on their theme.

You'll want to remove the where clause from there as that is going to make it only display images from one theme.

What you do instead is set the order to be based on the theme field. You can do that in the view code directly or in the section editor.

Let me know if this sounds right. Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] How to deal with displaying several result generated with "WHERE" condition

Yes you are right!
I tryed to use 'orderBy', it works, but i need to group by theme, for exemple separate each group with <br/><br/>

Re: [ross] How to deal with displaying several result generated with "WHERE" condition

By willbegood - April 1, 2009

Hello, here is my code, please also watch the attachment schema to see how i would it to be displayed.
Also how to do if i want group of theme to be displayed in a precise order for exemple : theme3, theme1, theme2

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/var/www/vhosts/test.com/httpdocs/admin/lib/viewer_functions.php";

list($posterRecords, $posterMetaData) = getRecords(array(
'tableName' => 'poster',
'orderBy' => 'theme',
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title></title>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="4">
<tr>
<?php foreach ($posterRecords as $record): ?>
<!-- This below break the table design because of the maxcols stuff -->
<h2><?php echo $record['theme'] ?></h2>
<!-- ///////////////////////////////////////////////////////////// -->
<?php foreach ($record['photo'] as $upload): ?>
<td width="20%" align="left" valign="top">
<div align="center">
<a href="<?php echo $upload['urlPath'] ?>" class="thickbox" rel="a" title="<?php echo $record['title'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" alt="" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" /></a> <br /><?php echo $record['title'] ?>

</td>
<?php $maxCols=4; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif ?>
<?php endforeach ?>
<?php endforeach; ?>
</tr>
</table>



</body>
</html>

Attachments:

schema.jpg 86K

Re: [willbegood] How to deal with displaying several result generated with "WHERE" condition

By ross - April 1, 2009

Hi.

Thanks for getting me that code. I have a new copy of your page attached to this post. I've added a new variable called $lastTheme.

I added comment tags around the new code like this:
<!-- code added by Ross -->

Each time it goes through the loop, the code checks if the current theme equals $lastTheme. If it doesn't, it will add a break, display the new theme name and then keep on going.

It's a little tricky for me to fully test this out as I don't have all your data so you might need to tweak it a bit. Give it a shot though and see if it gets you going.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Attachments:

sample.php 2K

Re: [ross] How to deal with displaying several result generated with "WHERE" condition

By willbegood - April 1, 2009

Thanks ross,

I tryed your code, i get an error

Notice: Undefined variable: record in /var/www/vhosts/test.com/httpdocs/fr/sample.php on line 24

and under this it display
Theme 1 and the picture of Theme1... that's all
I doesn't show other image grouped in theme2 for exemple.

on line 24 there is : <?php $lastTheme; ?>

See attachment how my editor is setup, perhaps it can help.
Attachments:

aaaa1238619441444.png 73K

Re: [willbegood] How to deal with displaying several result generated with "WHERE" condition

By ross - April 2, 2009

Hi there.

Could you try changing this line:

<?php $lastTheme; ?>

to

<?php $lastTheme = ''; ?>

If that doesn't get things going, we'll likely need to get me some FTP details (through email: consulting@interactivetools.com) so I can actually test it out on your server. Right now, I am a little blind so it's hard to see exactly what's happening.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] How to deal with displaying several result generated with "WHERE" condition

By willbegood - April 2, 2009

Ross, no error anymore but see attachment how it display.
It list all the "theme" name and then the image.
Each of the image on my screenshot belong to a different theme.

Also please find my editor file (sorry i posted it on another thread)

Re: [willbegood] How to deal with displaying several result generated with "WHERE" condition

By ross - April 3, 2009

Hi

We are definitely on the right track here I think. What I suggest doing is just removing all the code that displays the images for now. Get it going perfectly with just a list of themes.

Then, start putting the images back in there. I suspect the problem might be with the tables you are using. I don't think my code additions took your tables properly.

Get it working with just the theme names and then start adding the tables back and then the images.

Keep me up to date with how you are making out :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/