You are here:  » Show if not null

Support Forum



Show if not null

Submitted by philstone on Fri, 2011-08-12 09:56 in

Hi David

Trying to get this bit of code working that will show a field if not null on the product page

<?php
 foreach ((array)$product["brand"] as $item) {
if(!empty($item['view'])){
echo "(Brand: <b>"; print $product["brand"];
}
}
?></b>

I can't figure out how to make this text a link without causing an error? would you be able to help me with this? or is there a better code to do this?

Regards

Phil

Submitted by support on Fri, 2011-08-12 11:16

Hi Phil,

To display all, perhaps something like this:

<?php
  
foreach($product as $key => $value)
  {
    if (
$value)
    {
      print 
"<p>".$k.": ".$v."</p>";
    }
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Fri, 2011-08-12 11:47

Hi david

thanks for that, not really what I was looking, if you see one of my product pages say {link saved}, underneath each merchant price I am displaying Brand, Model and EAN values as links, what I was looking was if one of these fields is empty to show nothing including the ean/brand/model text, the code below works to display it as text only, but I want to make it a link, like it is at the moment and not just text but i cant make it into a link with my limited php knowledge, if you have any code could help me do this?

<?php
 foreach ((array)$product["sku"] as $item) {
if(!empty($item['view'])){
echo "<font color=red>Product EAN/UPC: [ <b>"; print $product["sku"];
echo " ] ";
}
}
?></b></font>

I have displayed the code above in red on the prices.php page for the time being underneath the old code to show you what I mean, If you scroll down the page you will see nothing display when the field is empty.

thanks

Phil Stone
www.buy24-7.net

Submitted by support on Fri, 2011-08-12 12:40

Hi Phil,

Have a go with just;

<?php
 if ($product["sku"] <> "")
 {
   echo "Product EAN/UPC: [ <b><a href='".$config_baseHREF."search.php?q=".urlencode($q)."'>".$product["sku"]."</a></b> ] ";
 }
?></b></font>

Cheers,
David.
--
PriceTapestry.com

Submitted by philstone on Fri, 2011-08-12 12:53

Thanks David

that works like a dream!!

regards

Phil Stone
www.buy24-7.net