<?php
$name = "{{t_33}}";
$y=$name;
for($i=$y;$i<24;$i++) { ?>
<li>
<a class="<?php
if (($i>0 and $i<4) || ($i>20 and $i<24)) echo 'dark';
else if (($i>3 and $i<8)|| ($i>16 and $i<21)) echo 'light';
else if ($i>7 and $i<17) echo ''; ?>"
href="#">
<?php echo $i; ?>
</a>
<?php if($i==1) { ?>
<h4>{{day}}</h4>
<?php } ?>
</li>
<?php } ?>
The issue is that I am getting the value in $name but when I assign it in $y and try to use it in for loop the page goes blank. Please help.
I think that issue is with order of processing your code. You should know that php is interpreted on server side and javascript is procesed on client side.
Now when your angular is code running, php functions are already processed. (I'm simplyfing here ofc.)
Related
Hi I have used some code but I want it so when the name is NULL it is hidden, if this is possible please help.
Here is the code
<p id="top"><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>Welcome To the homepage of The Journalist's</p>
I want it to be when name is NULL, for
"<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]"
to be hidden.
Thank you.
update...
This is what i have so far
This is what i have so far.
<?php
if ($SESSION['name']= NULL) {
?>
<div><strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]</div>
<?php
}
?>
I have fixed it , thank you for everyone that has commented. for anyone else with this problem. here is my solution.
<?php
if ($_SESSION['name']!= NULL) {
?>
<strong>Welcome back <?php echo $_SESSION['name']; ?> [Logout]<br/>
<?php
}
?>
Update from your posted code:
For one, you are using $SESSION instead of $_SESSION. Second, you are setting $SESSION['name'] using a single equal sign, so the if condition would always fail because it is evaluating if (NULL). You need to use == or ===. Read up on comparison operators.
<?php
if (condition) {
?>
<div></div>
<?php
}
?>
I apologize for any misuse of terminology...I'm a noob...
I have a dynamically created page that contains a dynamic link. I added an IF/ELSE statement to display a different word based on the number of items in the variable $rowsphoto.
The different words display correctly, but the URL that is generated contains all of the PHP instead of generating the correct URL.
This is the original code, which works fine:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">Additional works in Portfolio:</div>
This is the code I have after adding the IF/ELSE statement:
<?php if($portfolioid != 0) { ?>
<div class="extrafield">
<?php
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid;?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid;?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
?>
</div>
I ran the code through a couple syntax checks and they all came back with no errors. What am I doing wrong? Is this even possible?
You'd be better off using it correctly like this:
<?php if($portfolioid != 0): ?>
<div class="extrafield">
<?php if($rowsphoto <= 4): ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Edition:</a>
<?php else: ?>
Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=<?php echo $artistid; ?>&pid=<?php echo $portfolioid; ?>&album=<?php echo $albumid; ?>&id=<?php echo $photoidd; ?>&Itemid=105' class='portfoliocol'>Portfolio:</a>
<?php endif; ?>
</div>
<?php endif; ?>
You're mixing html and php very badly. You should be separating them to keep your code clean and concise.
Your issue with it displaying the php instead of the correct variables is because (as #scrowler said):
You can't use PHP tags inside PHP, you just need to escape the string
bounds and use the . concatenation operator instead of trying to open
new PHP tags, e.g. echo "String here" . $varname; as opposed to echo
"String here"
While Darren's answer is correct, alternatively you can just stay inside of php
<?php
if($portfolioid != 0) {
echo '<div class="extrafield">';
if ($rowsphoto <= 4){
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Edition:</a>";
} else {
echo "Additional works in <a href='index.php?option=com_jartists&view=portfolio&aid=$artistid&pid=$portfolioid&album=$albumid&id=$photoidd&Itemid=105' class='portfoliocol'>Portfolio:</a>";
}
echo '</div>';
}
?>
Here is the code I have:
in the php file:
if($special>0){
$lease_price = (($special/1000)*38);
} else {
$lease_price = (($price/1000)*38);
}
$lease_price = $this->currency->format($lease_price);
and in the front end tpl file:
<p>
<i class="fa fa-chevron-down"></i>
<b>Lease To Buy Price:</b>
<span><?php if($price>500){ ?>
<?php echo $lease_price; ?>
<?php } else { echo 'NA'; } ?></span>
</p>
Now I believe this works, but I think I'm entering the php code in the wrong area of the php document which is causing the variable $lease_price to not work.
Here's a link to a pastebin of my php file, where would I enter the code above? http://pastebin.com/bTPtvgUQ
Thanks for the help
I have created a homepage editor tool in a script I purchased. The function of this homepage editor is to allow me to create different sections and display them one on top of the other in the order they are created. Which in hopes will give me an effect of several blocks that stretch width of the screen.
All seems to work well except one piece. I input my html and php code into the field in the admin panel and it saves to the db as I wrote it. However, when I go to echo each section back to the homepage it just displays my php code as plain text and doesn't interpret it as php and do its function.
Here is code from the homepage.php that prints the results.
<?php
session_start();
require_once("inc/config.inc.php");
if (isset($_GET['ref']) && is_numeric($_GET['ref']))
{
$ref_id = (int)$_GET['ref'];
setReferal($ref_id);
header("Location: index.php");
exit();
}
/////////////// Page config ///////////////
function get_all_section($section_id='')
{
$sql="SELECT * FROM `cashbackengine_homepage` WHERE 1";
if($section_id!="")
{
$sql.=" AND section_id='".$section_id."'";
}
$sql.=" AND section_status=1";
$sql.=" ORDER BY section_order ASC";
//echo $sql;
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
$section_array[]=array(
'section_id' =>$row['section_id'],
'section_name' =>$row['section_name'],
'section_desc' =>$row['section_desc'],
'section_order' =>$row['section_order'],
'section_status' =>$row['section_status'],
'last_updated' =>$row['last_updated'],
);
}
return $section_array;
}
$get_all_section=get_all_section('');
/*$get_all_section2=get_all_section('2');
$get_all_section3=get_all_section('3');
$get_all_section4=get_all_section('4');
$get_all_section5=get_all_section('5');*/
for($i=0; $i<count($get_all_section);$i++)
{
//echo htmlspecialchars_decode($get_all_section[$i]['section_desc']);
//echo htmlspecialchars_decode(stripslashes(str_replace(" ","",(str_replace("<br />","\n",$get_all_section[$i]['section_desc'])))));
echo $get_all_section[$i]['section_desc'];
}
?>
I am certain the problem has to do with the echo at the end. But I am unsure how to use htmlspecialchars to make it work with php if it even will. Or if I have to put something weird in my saved section.
Here is one of my sections. Any help is greatly appreciated. Thank you.
<div style="height:260px; width:100%; background-color:#000; margin:0px; color:white;">
<div id="header">
<div id="logo"><img src="<?php echo SITE_URL; ?>images/logo.png" alt="<?php echo SITE_TITLE; ?>" title="<?php echo SITE_TITLE; ?>" border="0" /></div>
<div class="start_saving">
<div id="links">
<?php if (MULTILINGUAL == 1 && count($languages) > 0) { ?>
<div id="languages">
<?php foreach ($languages AS $language_code => $language) { ?>
<img src="<?php echo SITE_URL; ?>images/flags/<?php echo $language_code; ?>.png" alt="<?php echo $language; ?>" border="0" />
<?php } ?>
</div>
<?php } ?>
<div id="welcome">
<?php if (isLoggedIn()) { ?>
<?php echo CBE_WELCOME; ?>, <span class="member"><?php echo $_SESSION['FirstName']; ?></span><!-- | <?php echo CBE_ACCOUNT ?>--> | <?php echo CBE_BALANCE; ?>: <span class="mbalance"><?php echo GetUserBalance($_SESSION['userid']); ?></span> | <?php echo CBE_REFERRALS; ?>: <span class="referrals"><?php echo GetReferralsTotal($_SESSION['userid']); ?></span>
<?php }else{ ?>
<a class="signup" href="<?php echo SITE_URL; ?>signup.php"><?php echo CBE_SIGNUP; ?></a> <a class="login" href="<?php echo SITE_URL; ?>login.php"><?php echo CBE_LOGIN; ?></a>
<?php } ?>
</div>
</div></div>
</div>
It looks like you're getting these section contents pieces out of your database, and not from a file stored on your web server. Is that correct?
Assuming that's true, then my next question would be, who populates this data? Is this taken in any way from user input? The reason why I ask is because of my next suggestion, which may or may not be received well.
The reason why your PHP code isn't executing, is because it's being retrieved from the database and output as a string, not as code. So how do you execute code that's stored in a string, you ask? Well, the answer to that question is to use eval() on the string. But this is where you have to be really careful!!!!!!! If any part of that string could have possibly come from an untrusted source, then malicious PHP code could be executed, which could potentially give evildoers a way into your server, where they can find all the information in your database, server, etc. Make sure you know where your code is coming from before executing it!
You make a good point that it's HTML mixed with PHP. So I see two possible solutions...
This post suggests that you could do eval(' ?>'. $section .' <?php'); This makes sense, you're breaking out of PHP before you eval your string, and so requiring the included string to open its own PHP tags to write PHP code.
Another way I can think of would be to throw the contents into a temporary file, and then include() that file:
// get contents, store in $contents
$filename = tempnam(sys_get_temp_dir(), 'section');
file_put_contents($filename, $section);
include($filename);
unlink($filename);
I'm using the following section of code to display some icons on our Magento store with the idea being if there is nothing added in the icons section it shouldn't display, for some reason this isn't working...it is displaying a division as if something is there but there is actually nothing.
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons') !== null):
?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->geticons()), 'icons') ?>
</div>
<?php endif; ?>
It needs to show Icons if they are coded in the attribute field and then hide the division if there is nothing added.
I've worked out that the code is returning a value of string(0) what do I need to change in my coding to get the desired effect?
Here's the thing you need, and you don't need call the same functionality twice to get the empty result. Define your variable and check if it is empty (null, undefined or false) or not
<?php $icons = $_helper->productAttribute($_product,($_product->getIcons()), 'icons');?>
<?php if(!empty($icons)):?>
<div class="product-icons">
<?php echo $icons;?>
</div>
<?php endif;?>
this could be even better solution as it wont call the helper unless there are icons defined but you first have to try it out on your codebase.
<?php if($_product->getIcons()):?>
<div class="product-icons">
<?php echo $_helper->productAttribute($_product,($_product->getIcons()), 'icons') ?>
</div>
<?php endif; ?>
and please check if it isn't a typo and it really is:
$_product->geticons()
or should it be
$_product->getIcons()
Something like:
<?php
if($_helper->productAttribute($_product,($_product->geticons()), 'icons'))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>
would be better!
try
<?php
if(!empty($_helper->productAttribute($_product,($_product->geticons()), 'icons')))
{
echo "<div class=\"product-icons\">";
echo $_helper->productAttribute($_product,($_product->geticons()), 'icons');
echo "</div>";
}
?>