NAmeviolated Posted October 23, 2011 Share Posted October 23, 2011 Sorry going to be a big post, but trying to query a sql database for a value Original code <?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?> <!-- Item extra fields --> <div class="catItemExtraFields"> <h4><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></h4> <ul> <?php foreach ($this->item->extra_fields as $key=>$extraField): ?> <?php if($extraField->value): ?> <li class="<?php echo ($key%2) ? "odd" : "even"; ?> type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>"> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> </li> <?php endif; ?> <?php endforeach; ?> </ul> <div class="clr"></div> </div> <?php endif; ?> Now I want to check the name field for a value and if it is Closing Date print out something different from the value in value, so I've changed the red code to <span class="catItemExtraFieldsLabel"><?php if $extraField->name ="Closing date"; ?></span> { <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $this->item->publish_down, JText::_('K2_DATE_FORMAT_LC2')); ?></span> } else { <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> } <?php endif; ?> Doesn't work though, tried a heap of variations but can't figure it out. Thanks Marc Quote Link to comment https://forums.phpfreaks.com/topic/249625-check-sql-database-for-value-if-statement/ Share on other sites More sharing options...
Ortix Posted October 23, 2011 Share Posted October 23, 2011 ahh the good old K2. Working with that as well! Good stuff! I think you are misinterpreting the way K2 is coded. It should be this: <span class="catItemExtraFieldsLabel"><?php if ($extraField->name ="Closing date") : ?></span> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $this->item->publish_down,JText::_('K2_DATE_FORMAT_LC2')); ?></span> <?php else :?> <span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span> <span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span> <?php endif; ?> But you are doing something wrong where you try to echo the publish_down and the date... What is it that you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/249625-check-sql-database-for-value-if-statement/#findComment-1281516 Share on other sites More sharing options...
NAmeviolated Posted October 23, 2011 Author Share Posted October 23, 2011 I have a extra Field called Closing Date, the publish_down is the date where it is stored. The L2 date is right as well, I pulled that from elsewhere. Problem is the actual IF syntax on testing the string. Quote Link to comment https://forums.phpfreaks.com/topic/249625-check-sql-database-for-value-if-statement/#findComment-1281519 Share on other sites More sharing options...
NAmeviolated Posted October 24, 2011 Author Share Posted October 24, 2011 Your code worked once I found that I had a extra ) in it. Now trying to work out how to format that value to display the date in a different format, as the L2/L4 doesn't work. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/249625-check-sql-database-for-value-if-statement/#findComment-1281699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.