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'])){
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 .
?>
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
Having a small issue here but cannot figure out where I have gone wrong. I have the following code which should show an image depending on the condition but instead it shows the HTML in the browser
if ($this->id_status == 2)
{
$this->id_status = "<img src='../_lib/img/gray_dot.png' />";
}
elseif ($this->id_status == 1)
{
$this->id_status = "<img src='../_lib/img/green_dot.png' />";
}
elseif ($this->id_status == 3)
{
$this->id_status = "<img src='../_lib/img/orange_dot.png' />";
}
Can anyone help?
try this:
<?php
if ($this->id_status == 2)
{
?>
<img src='../_lib/img/gray_dot.png' />
<?php
}
elseif ($this->id_status == 1)
{
?>
<img src='../_lib/img/green_dot.png' />
<?php
}
elseif ($this->id_status == 3)
{
?>
<img src='../_lib/img/orange_dot.png' />
<?php
}
?>
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'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>