Problem with elseif statements

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2010   (RSS)

By Mel - February 24, 2010

Hi

I have a problem with else if statements, even after having read the cook book now I know why I did not pass my programming test when I was a teenager[blush]

So here is the problem and the code is below

I am selecting all records with a specific product type and these product types exist in various regions

<?php


require_once "C:/wamp/www/mel365/cmsAdmin/lib/viewer_functions.php";



list($biosRecords, $biosDetails) = getRecords(array(
'tableName' => 'bios',
'perPage' => '10',
'where' => ' type = "1"' ,


));

?>

This works and only selects records of type 1

Now I have regions lets say 10 in all, including " North West " " East Midlands " etc etc

I am running the test with two regions and what is happening is that the same identical records are being displayed in each region

On my test set up I have just one record for [region] north west and one for [region] east midlands - but both records are being displayed in both regions

What am I doing wrong here and how do I set the if statements up for 2 regions+

What I want to achieve is

Region One
type one record
type one record
type one record

Region Two
type one record
type one record
type one record

Region Two
type one record
type one record
type one record

etc. etc. etc.


Here is my code:

<!--Begin record display-->

<?php foreach ($biosRecords as $biosRecord): ?>

<!--North West -->

<?php if ($biosRecord['region'] = 'north west'):?>

<h1>North West</h1>

<div class="panel">

<div>

<h2><?php echo $biosRecord['name'] ?></h2>
</div>
<div class="picbiocontainer"><div class="thumbpic">
<?php foreach ($biosRecord['newimage'] as $upload): ?>

<?php if ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php endif ?>

<?php endforeach ?></div>

<div class="biopanel"><?php echo $biosRecord['bio'] ?></div>

<div class="clickLink1"><a href="<?php echo $biosRecord['_link'] ?>">Click to view details</a></div>
</div>

</div><!-- end panel -->

<?php endif ?>
<!--Finish of North West-->

<!--Start East Midlands-->

<?php if ($biosRecord['region'] = 'east midlands'):?>

<h1>East Midlands</h1>

<div class="panel">

<div>

<h2><?php echo $biosRecord['name'] ?></h2>
</div>
<div class="picbiocontainer"><div class="thumbpic">
<?php foreach ($biosRecord['newimage'] as $upload): ?>

<?php if ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<?php endif ?>

<?php endforeach ?></div>

<div class="biopanel"><?php echo $biosRecord['bio'] ?></div>

<div class="clickLink1"><a href="<?php echo $biosRecord['_link'] ?>">Click to view details</a></div>
</div>

</div><!-- end panel -->

<?php endif ?>
<?php endforeach ?>




Thanks Mel

Re: [mel] Problem with elseif statements

By Dave - February 24, 2010

Hi Mel,

There's may be a number of issues to resolve, but start by adding an extra = like this:

<?php if ($biosRecord['region'] == 'north west'):?>
<?php if ($biosRecord['region'] == 'east midlands'):?>

= assigns a value, setting region to the text, where as == compares values, checking if they are equal.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com