Conditional Display of Field
8 posts by 4 authors in: Forums > CMS Builder
Last Post: July 27, 2009 (RSS)
By theclicklab - July 18, 2009
E.g. when I go to:
www.domain.com/listviewer.php/type-value-a/
www.domain.com/listviewer.php/type-value-b
www.domain.com/listviewer.php/type-value-c/
So I assume I need something like this
if type = Value A
<h1>Value A</h1>
elseif type = Value B
<h1>Value B</h1>
else type = Value C
<h1>Value C</h1>
Not sure on what code to use though. Any suggestions?
Many thanks.
Re: [aquaman] Conditional Display of Field
By gkornbluth - July 19, 2009
If you think that an "If" statement will do the job for you, then here's some code that should work for you.
The first rule to remember is that every (series of) if statement(s) must be closed with an <?php endif ?> in order for them to work correctly.
The second rule is that if you’re using a series of if statements, then the first one is always an “if”, the last is always “else” and any in the middle are “elseif”.
If you wanted to test for particular contents in “your_field”. Say, if the contents of “your_field” equaled “apples” then, you’d use the exactly equal to “==” operator:
in a detail viewer (single record):
<?php if ($your_tableRecord['your_field'] == 'apples'): ?><h1>your field contains apples</h1>
<?php elseif ($your_tableRecord['your_field'] == 'bananas'): ?> <h1>your field contains bananas</h1>
<?php else: ?><h1>your field contains no apples or bananas</h1>
<?php endif ?>
And in a list viewer(multi record) :
<?php foreach ($your_tableRecords as $record): ?>
<?php if ($record['your_field'] == 'apples'): ?><h1>your field contains apples</h1>
<?php elseif ($record['your_field'] == 'bananas'): ?> <h1>your field contains bananas</h1>
<?php else: ?><h1>your field contains no apples or bananas</h1>
<?php endif ?>
<?php endforeach; ?>
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Conditional Display of Field
By theclicklab - July 19, 2009
Thanks for that it worked with the addition of <?php break ?>
But I think I'm trying to do this the wrong way because it grabs the first record when showing "ALL" types and if there are no records then it dos not show anything.
example - see red text: http://www.staging.baobabmarine.com/brokerage.php
changing the drop-down displays the three different types.
Is there a better way of doing this?
Re: [aquaman] Conditional Display of Field
By ross - July 21, 2009
Thanks for posting!
Could you post a copy of that whole page you are working with? Best case scenario would be if you could attach the file instead of pasting code into a post.
I'll take a look at how you have things setup and see what options you have. I definitely think you are on the right track and Jerry's tips on if blocks was great.
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] Conditional Display of Field
By theclicklab - July 21, 2009
Re: [aquaman] Conditional Display of Field
By ross - July 24, 2009
I've been looking through that code and usually, if you just go to brokerage.php without any search criteria, it will display all your records. The only thing right now is that the link to this page on your site doesn't actually work anymore. Could you send me an up to date link?
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] Conditional Display of Field
By theclicklab - July 24, 2009
Re: [aquaman] Conditional Display of Field
By Dave - July 27, 2009
Are you still working on displaying a different heading based on the seo url variable?
If so, you can test urls like this:
www.domain.com/listviewer.php/type-value-a/
www.domain.com/listviewer.php/type-value-b
With this code:
<?php if (@$_REQUEST['type'] == 'value-a'): ?>
Value A
<?php endif ?>
<?php if (@$_REQUEST['type'] == 'value-b'): ?>
Value B
<?php endif ?>
Let me know if that works for you.
interactivetools.com