Detail Page - check List needs to show image

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 2, 2014   (RSS)

By thenetgirl - April 1, 2014

Help Please

http://comfy.exedor.us/productDetail.php?3 - this shouldn't have a cool image

This is in my section editor

Type (values): <?php echo join(', ', $productsRecord['type:values']); ?><br/>
Type (labels): <?php echo join(', ', $productsRecord['type:labels']); ?><br/>

------------------------------------------------- This is what I put..it shows the images alright - all of them all the time no matter what I check -----------

<?php if (strpos($productsRecord['type'],"\tWarm\t") !== 1) : ?>

<img src="http://comfy.exedor.us/images/warm1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

<?php if (strpos($productsRecord['type'],"\tSmell\t") !== 3) : ?>
<img src="http://comfy.exedor.us/images/smell1.gif" border="0" width="47" height="47" ></a>

<?php endif; ?>


<?php if (strpos($productsRecord['type'],"\tCool\t") !== 2) : ?>
<img src="http://comfy.exedor.us/images/cold1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

thanks

Patricia

www.thenetgirl.com

By Chris - April 2, 2014

strpos() returns FALSE if the "needle" isn't found in the "haystack". If it is found, it returns the character position of the start of the first match. Note that it can return 0 if the needle is found at the very start of the haystack. For example:

var_export(strpos("haystack haystack haystack NEEDLE haystack", "NEEDLE")); // outputs "27"
var_export(strpos("NEEDLE haystack haystack haystack haystack", "NEEDLE")); // outputs "0"
var_export(strpos("haystack haystack haystack haystack", "NEEDLE"));        // outputs "false"

Because 0 can seem like FALSE to PHP, to check if a string contains another string, it's important to use a strict equality test to check for FALSE:

var_export(strpos("haystack haystack haystack NEEDLE haystack", "NEEDLE") !== FALSE); // outputs "true"
var_export(strpos("NEEDLE haystack haystack haystack haystack", "NEEDLE") !== FALSE); // outputs "true"
var_export(strpos("haystack haystack haystack haystack", "NEEDLE") !== FALSE);        // outputs "false"

Alternately, if you're using CMS Builder version 2.50 or newer, you can use the contains() function, but note well that the order of the needle and haystack arguments are flipped:

var_export(contains("NEEDLE", "haystack haystack haystack NEEDLE haystack")); // outputs "true"
var_export(contains("NEEDLE", "NEEDLE haystack haystack haystack haystack")); // outputs "true"
var_export(contains("NEEDLE", "haystack haystack haystack haystack"));        // outputs "false"

Does this work for you?

<?php if (contains("\tWarm\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/warm1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

<?php if (contains("\tSmell\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/smell1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

<?php if (contains("\tCool\t", $productsRecord['type'])) : ?>
  <img src="http://comfy.exedor.us/images/cold1.gif" border="0" width="47" height="47" ></a>
<?php endif; ?>

All the best,
Chris