Little help needed with elseif and if statement

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 27, 2014   (RSS)

By rconring - July 23, 2014

If I were doing this, I would create 2 variables, one for target URL and one for target frame.  Then I would only use one hyperlink reference using the 2 variables:

<?php 
    if ($record['internal_page']) {$targetURL = $record['_link'] ;}
    elseif ($record['external_link']) {$targetURL = $record['external_link'] ;}

    if ($record['open_in_same_window']) {$targetFrame = "_self" ;}
    else {$targetFrame = "_blank" ;}
?>    
<a target="<?php echo $targetFrame ?>" href="<?php echo $targetURL ?>"> 
    <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $upload['info1'] ?>" />
</a>

I can't test this code, but  it should work because I do it frequently almost the same way except reverse.  My target frame variable is a check box to open in new window.  I hope this will help you.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By sublmnl - July 27, 2014

That works. Makes sense too.

Thanks a lot. One of the reasons why I love using iTools, is the support from the team and the community.

One thing that was missing in your code was the last ELSE which was to not link any text or image at all.

So I went ahead and added another checkbox for the 'new' option in the CMS and wrapped your code with a single IF -> ELSE -> endIF

I'm sure there is probably another way to do this, like to check for whether or not there is an External Link in the text Field or if the checkbox is checked for the Internal Page.

But this is what I did (it works):

<?php foreach ($record['list_image'] as $index => $upload): ?>
<?php if ($record['link_activity_to_another_page']):?>
        <?php 
    if ($record['internal_page']) {$targetURL = $record['_link'] ;}
    elseif ($record['external_link']) {$targetURL = $record['external_link'] ;}

    if ($record['open_in_same_window']) {$targetFrame = "_self" ;}
    else {$targetFrame = "_blank" ;}
?>    
<a target="<?php echo $targetFrame ?>" href="<?php echo $targetURL ?>"> 
    <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $upload['info1'] ?>" />
</a>
<?php else:?><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $upload['info1'] ?>" /><?php endif ?>
<?php endforeach ?>

By rconring - July 27, 2014

Yes, there are scads of variations ... I was just demonstrating the fundamental logic. 

And yes, this forum is invaluable!  I have learned everything I know about PHP-MySQL programming from mainly this forum and others such as Stack Overflow.  When I purchased CMS Builder a few years back, I knew NOTHING about web development.  I took a chance on CMSB and am very glad I did.  Between their support team and the user community I can get just about anything resolved.

I am happy to give back if I can.

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987