You are here:  » PHP ElseIf Error

Support Forum



PHP ElseIf Error

Submitted by webie on Tue, 2009-07-28 13:25 in

Hi Dave,

I been trying to add some code on the product page to check if the product description is under 100 charactors in length to print a deafault description and also is the description field is empty to print default description this what i got but its not working?

<?php if (count(count_chars($mainProduct["description"], 1)) < 20)
{
         print $default_desc;
}
elseif ($mainProduct["description"] = NULL)
{
print $default_desc;
} else {
print $mainProduct["description"];
} ?>

Kind Regards

Darren

Submitted by support on Tue, 2009-07-28 14:31

Hi Darren,

A single test should cover both scenarios (as description defaults to "" rather than NULL) - have a go with:

<?php
if (strlen($mainProduct["description"]) < 100)
{
  print 
$default_desc;
}
else
{
  print 
$mainProduct["description"];
}
?>

Cheers,
David.