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
Related
In opencart 2.2 product.tpl file I found the following code which is quite confusing to me:
<div class="row" style="padding-top:10px"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
Specifically, I'm not able to understand how they can use ?> inside curly brackets of if statement? More important, I tried to revise the above code as following but then it stopped working:
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) {
$class = 'col-sm-6';
}
elseif ($column_left || $column_right) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
?>
Any explanations?
There is no mistake in the php code.
You can open and close a php tag as much as you like. During run time the files are processed and all the php code is interpreted each line at a time.
So it is fine to write like this
<?php echo 'hello';
echo 'world';
?>
as well as this
<?php echo 'hello'; ?>
<?php echo 'world'; ?>
The only reason why OpenCart uses the later style is becuase it is a bit nicer since the <?php tag creates a column and is a bit easier to read.
Its clearly visible, there is syntax error for if. You can't use elseif without if.
<?php
if ($check) {
// Code...
} elseif ($check_2) {
// Code...
}
?>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) {
$class = 'col-sm-6';
}
elseif ($column_left || $column_right) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
} // this is missing in your case
?>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) {
$class = 'col-sm-6';
}
elseif ($column_left || $column_right) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
} // you have missed this "}" for the else .
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I’m going mad over this – I can’t find the reason for the "unexpected {"-error being thrown right after the last "else" (7th line from below). Does anyone see something that I don’t?
<?php
$i = 0;
foreach($bgs as $bg) { ?>
<?php $i++; ?>
<div class="item <?php if($i == '1') echo "active"; ?> img-responsive" style="background-image: url('/new/images/<?=$bg['b_url']?>')" >
<div class="metabox">
<?php if(($bg['b_weight']) != '1000') { ?>
<h1><?=$bg['w_titel']?></h1>
<p><?=$bg['w_info']?> // <?=$bg['w_jahr']?> // <?=$bg['w_ort']?><?=$bg['w_function']?></p>
<?php if (isset($_GET['w']) && (is_numeric($_GET['w']))) { ?>
<?=$bg['w_desc']?>
<?php } else { ?>
<p>More</p>
<?php } ?>
<?php } else { ?>
<h1><?=$bg['w_titel']?></h1>
<p><?=$bg['w_info']?></p>
<?php } ?>
</div>
</div>
<?php } ?>
This is very hard to read, you have my sympathies. Have you thought about using an alternative syntax for if
try using
<?php if (condition) :?> <?php do something; ?>
<?php else: do something; ?>
<?php endif; ?>
This was odd: Right before said last else statement was an invisible item (have no idea what it could have been?) – when I deleted the space between the preceding } and else, and inserted a new blank space, the code parsed fine.
Everything looks right. Try to use following syntax it will be more readable.
foreach($bgs as $bg) :
$i++;
if(1 != '1000') :
echo 3;
if ( 1 != 2) :
echo 4;
else:
echo 1;
endif;
else:
echo 2;
endif;
endforeach;
Also try to replace:
<?php if($i == '1') echo "active"; ?>
to:
<?= $i == '1' ? "active" : ''; ?>
I am creating an responsive template and for that to happen I need to use and if else and function. This is what I have so far.
<?php if ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
I am now receiving the error:
Parse error: syntax error, unexpected '&&' (T_BOOLEAN_AND) in index.php on line 197
Line 197 =
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
I have tried adding an extra () but that did not work:
<?php } elseif (($this->countModules('left')) && ($this->countModules('right'))) { ?>
I am forgetting something but what.
The order is wrong and instead of adding the () you should remove a set. See the adapted code below.
<?php if ($this->countModules('left') && $this->countModules('right')) { ?>
<p>Left + Right + Content</p>
<?php } elseif ($this->countModules('right')) { ?>
<p>Right + Content</p>
<?php } elseif ($this->countModules('left')) { ?>
<p>Left + Content</p>
<?php } else { ?>
<p>Content</p>
<?php } ?>
Hopefully this puts you in the right lane.
You have your brackets in the wrong place. Try replacing the following:
<?php } elseif ($this->countModules('left')) && ($this->countModules('right')) { ?>
with this:
<?php } elseif ($this->countModules('left') && $this->countModules('right')) { ?>
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'])){
What I'm trying to do is that any form with the $id that is less than 50 to use a certain A href else use another A HREF. This is what I have so far but I have no idea how to include it since it has php with in the HREF. How can I make this work. Thanks in advance.
</td>
<td>
<?php if($id <= 50) {
<?=$row[software]?>
}
else {
<?=$row[software]?>
}
?>
</td>
<td>
<?php if($id <= 50): ?>
<?=$row[software]?>
<?php else: ?>
<?=$row[software]?>
<?php endif; ?>
</td>
A cleaner way to do this would be to just use an if statement on the part of the anchor tag that changes (the modify/template bit):
<?=$row[software]?>
You can put this anywhere in a page that is parsed by PHP (doesn't matter that there's inline PHP in your HTML.
Exit PHP like this (easy enough - in your case you don't need to edit really, you just wrap the top example here in your <td> tags):
?>
<?=$row[software]?>
<?php
... or:
$action = $id <= 50 ? 'template' : 'modify';
echo '' . $row['software'] . '';
<?php
if($id <= 50) {
echo '' . $row['software'] . '';
} else {
echo ''. $row['software'] . '';
}
?>
printf() is your friend.
<td>
<?php
$frame = "%s";
if($id <= 50) {
printf($frame, $row[form_type], $row[id], $row[form_type], '***template***', $row[software]);
} else {
printf($frame, $row[form_type], $row[id], $row[form_type], '***modify***', $row[software]);
}
?>
</td>
</td>
<td>
<?php
if($id <= 50) {
echo ''.$row[software].'';
} else {
echo ''.$row[software].'';
}
?>
First of all, don't use the short tags <?=?>, this is considered bad practice.
Secondly, you may use this:
</td>
<td>
<?php if($id <= 50) { ?>
<?php echo $row[software]?>
<?php } else { ?>
<?php echo $row[software]?>
<?php } ?>
</td>