I am confused and not sure why this code is not working.
Here is the original code :
//start date to end date
<?php if($show5 < $show6) { ?>
<a>show content</a>
<?php }?>
If 'start date' and 'end date' values are empty then I want to remove or hide <?php if($show5 < $show6) { ?> <?php }?> and 'show content'.
And if 'start date' and 'end date' values are not empty then I want to remove or hide <?php if($show5 != '' && $show6 != '') { ?> <?php }?> and show content. If start to end date are not expired and if start to end date are expired then hide the content.
<?php if($show5 != '' && $show6 != '') { ?>
//start date to end date
<?php if($show5 < $show6) { ?>
<?php } ?>
<a>show content</a>
<?php if($show5 != '' && $show6 != '') { ?>
<?php } ?>
<?php }?>
is this what you were trying to do?
<?php if ($show5 != '' && $show6 != '') { ?>
//start date to end date
<?php if (strtotime($show5) < strtotime($show6)) { ?>
<a>show5 content</a>
<?php } ?>
<?php if (strtotime($show5) > strtotime($show6)) { ?>
<a>show6 content</a>
<?php } ?>
<?php } ?>
The bottom code was not necessary and therefore it was throwing an error. Also the html had to be moved few lines top and you were missing one <?php } ?>
I am not sure at all what are you trying to do... BTW, you don't need to put each sentence between <?php ?> brackets, just until you turn to html:
<?php if($show5 != '' && $show6 != '') {
//start date to end date
if($show5 < $show6) {
}?>
<a>show content</a> <<<---- This is outside the php block, if you want it inside you can do it with echo "<a>show content</a>";
<?php if($show5 != '' && $show6 != '') {
}
}?>
Update
<?php if($show5 != '' && $show6 != '') {
echo "<a>show content</a>";
}
else{
$curDate = date(); //currentDate
if($show5 <= $curDate && $curdate < $show6) {
echo "<a>show another content</a>";
}
}?>
Notice that the date() function can be formatted as you want to match $show5 and $show6. And viceversa, this variables can be formatted to match the date() format: https://secure.php.net/manual/es/function.date.php.
If you modify this code a bit you can make it post some content depending on many different parameters. Also, you could store the content in some other variables, and then post it after all of the ifs block
Related
With this code I'm trying to display an event date that has a beginning and ending date, but sometimes there is only one beginning date.
If there is a beginning and ending date i need this displayed:
DU 10 JUILLET 2017 AU 10 JUILLET 2017
And if there is only a beginning date, i need this displayed:
LE 10 JUILLET 2017 (the "DU" is replace by "LE")
<?php if (isset($this->item->jcfields[3]) && !empty($this->item-jcfields[3])):
?>Du
<?php echo FieldsHelper::render('com_content.article', 'field.render',
array('field'=> $this->item->jcfields[3])); ?>
<?php endif; ?>
<?php if (isset($this->item->jcfields[7]) && !trim($this->item-
>jcfields[7])): ?>Au
<?php echo FieldsHelper::render('com_content.article', 'field.render',
array('field'=> $this->item->jcfields[7])); ?>
<?php endif; ?>
Untested, and I tried to keep your code the same while improving formatting.
<?php
if (isset($this->item->jcfields[3]) && !empty($this->item->jcfields[3]) && $this->item->jcfields[3]->value != ''):
if (isset($this->item->jcfields[7]) && !empty($this->item->jcfields[7]) && $this->item->jcfields[7]->value != ''):
echo "Du ";
else:
echo "Le ";
endif;
echo FieldsHelper::render('com_content.article', 'field.render', array('field'=> $this->item->jcfields[3]));
if (isset($this->item->jcfields[7]) && !empty($this->item->jcfields[7]) && $this->item->jcfields[7]->value != ''):
echo " Au ";
echo FieldsHelper::render('com_content.article', 'field.render', array('field'=> $this->item->jcfields[7]));
endif;
endif;
I have tried
if ($row_products['psText'] != empty) {
and
if (!empty($row_products['psText'])) {
and
if (!is_null($row_products['psText'])) {
None of them work. However, if I echo out the echo $row_products['psText'], it has texts in there. Am I missing something here?
Okay, I'm updating my code. Below is the whole block of code. Perhaps my logic is wrong and not the code.
<?php do { ?>
<?php if($row_products['psLeft'] != ""){ ?>
<div id="left"><?php echo $row_products['psLeft']; ?></div>
<?php } if($row_products['psCenter'] != ""){ ?>
<div id="center"><?php echo $row_products['psCenter']; ?></div>
<? } if($row_products['psRight'] != ""){ ?>
<div id="right"><?php echo $row_products['psRight']; ?></div>
<? } if($row_products['psText'] != NULL && $row_products['psText'] != '' && !empty($row_products['psText'])){?>
<p>
<?php echo $row_products['psText']; ?>
</p>
<?php } else {echo 'Outside texts.'.$row_products['psText'];}?>
<?php } while ($row_products = mysql_fetch_assoc($products)); ?>
Try this
if ($row_products['psText'] != '') {
OR
if (strlen($row_products['psText']) !=0) {
OR
if(!empty($row_products['psText']))
I hope this helps you!!
You might try:
if ($row_products['psText'] != "") {
maybe following works:
if($row_products['psText'] != NULL && $row_products['psText'] != "" && !empty($row_products['psText'])){
I am using this code for Condtion but I dont know why the condtion is going False
<tr
<?php if ($LevelName['Status'] == 'Yes') { ?>
style="background:#DCFEB7"
<?php } ?>
<?php elseif (strtotime(date('Y-m-d h:i')) > strtotime($LevelName['ReportTime'])) { ?>
style="background:red"
<?php } ?>
<?php else { ?>
style="background:orange"
<?php } ?>
>
I don't know why the backgound color not going to Red
getting this result in condition:
(Todat Date)392291420 > (DB Date)1392336360
I am using Kirby for my CMS. I setup a custom field and when I have nothing inside it, it still outputs a blank line.
Backend screenshot showing no field value: http://cloud.chrisburton.me/LSyR
View Source showing blank line (52): http://cloud.chrisburton.me/LSW0
My Code:
<ul class="credits">
<?php
if($page->client() != '')
echo '<li><span>Client: </span>'.$page->client().'</li>';
?>
<?php
if($page->art_direction() != '')
echo '<li><span>Client: </span>'.$page->art_direcion().'</li>';
?>
<?php
if($page->typeface() != '')
echo '<li><span>Typeface: </span>'.$page->typeface().'</li>';
?>
</ul>
How can I remove that?
WYSIWYG.
I'd suggest different approach...
<ul class="credits">
<?php
foreach(array('Client' => $page->client(), 'Direction' => $page->art_direction(), 'Typeface' => $page->typeface()) as $key => $value)
if($value != '') echo "\t<li><span>{$key}: </span>{$value}</li>\n";
?>
</ul>
Also, make sure you don't indent <?php and that it starts from position 0.
http://ideone.com/MBWLU0
<ul class="credits">
<?php
if($page->client() != '')
echo '<li><span>Client: </span>'.$page->client().'</li>';
if($page->art_direction() != '')
echo '<li><span>Client: </span>'.$page->art_direcion().'</li>';
if($page->typeface() != '')
echo '<li><span>Typeface: </span>'.$page->typeface().'</li>';
?>
</ul>
I'm trying to specify that my logo appears on some pages and not on others, the only pages I do not want it showing on are the homepage and /index.php. I have the big logo appearing and disappearing as I want it and so I presumed I could just do the opposite for the small logo but I must be doing something wrong. Here is my current code:
<?php
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' || $dunpage != '/') {?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php }
?>
<?php
$currentpage = $_SERVER['REQUEST_URI']; if ($currentpage == '/' || $currentpage == '/index.php') {?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php }
?>
Instead of a logical OR in your first condition, you should be using a logical AND:
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' || $dunpage != '/') {?>
// Should be
$dunpage = $_SERVER['REQUEST_URI']; if ($dunpage != '/index.php' && $dunpage != '/') {?>
Effectively, you were saying "act if the page is either not index.php, or not /." So in either of those cases, the opposite would be true. If it wasn't index.php, it could be /, for example.
try
if ($dunpage != '/index.php' && $dunpage != '/') {
for your small logo.
You correctly negated the == operator, but not the || operator. You're saying that if dunpage is not /index.php OR dunpage is not /, do that, which basically means do that always. Change || to && for the small logo.
Why don't you use an else?
<?php
$currentpage = $_SERVER['REQUEST_URI']; if ($currentpage == '/' || $currentpage == '/index.php') { ?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php
} else {
?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php
}
?>
(You don't actually mention that it's either a large or a small logo that you want to display, but I have to assume that is the case here.)
Or you can use in_array() in this case.
<?php
$displayMainLogo = array('/', '/index.php');
if ( in_array($_SERVER['REQUEST_URI'], $displayMainLogo) ) { ?>
<h1 class="logo";>
<span><?php echo $siteName; ?>
</h1>
<?php
} else {
?>
<h1 class="small-logo">
<span><?php echo $siteName; ?>
</h1>
<?php
}
?>
If you understand how to do a ternary (http://php.net/manual/en/language.operators.comparison.php), then this is as terse as you can make it.
<h1 class="<?php echo (in_array($_SERVER['REQUEST_URI'], $displayMainLogo)) ? 'logo' : 'small-logo' ?>";>
<span><?php echo $siteName; ?>
</h1>