Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I know its possible to apply inline styles to echo statements but can this be done with print statements as well?
In my pagination I have links to previous and next records using the greater and less than symbols <> and a running count of the current record against the total number of records. e.g.
<
1/2
or
>
2/2
I have styled them in css but want to decrease the size of the count only. If I make changes to the css the font size for the previous and next links and count all change, I only want to target the count.
<div class="nextcard"><?php if($nextlink != ""){ print ($nextlink."<br/>".$next."/".$count); } ?></div>
I have tried :
<div class="nextcard"><?php if($nextlink != ""){ print 'style=font:50px' ($nextlink."<br/>".$next."/".$count); } ?></div>
But get syntax errors.
One approach would be to add a class rather than inline styles. However, you have forgotten to append the string correctly.
Here is what I would personally do: (Note I replaced print with echo, TBH, there would be no different)
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span class="mark">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>
If you still want to style it inline, you should simply do:
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span style="font-size:50px;">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 10 months ago.
Improve this question
Hello there I have a php foreach loop running that is all working except one part. I am pulling in data from a local json file. The beginning foreach call looks like this:
<?php foreach($boatslips as $boatslip): ?>
One of the json fields is: "rent_sale_or_both" : "rent" (but that field can be rent, sale, or both,)
Lower down in the code after some other fields are successfully rendered and inside the foreach loop still i'm trying the below code to render out whether a boat slip is for rent, sale or both; and wanting to then be able to style 'rent' 'sale' or 'both' with css eventually.
<?php
if ($boatslip->rent_sale_or_both == rent) {
echo "rent";
}elseif ($boatslip->rent_sale_or_both == sale) {
echo "sale";
}else {
echo "both";
}
?>
Then some more html after the elseif.
At the end of the for each loop it is closed off properly with <?php endforeach; ?>
Obviously this is probably not correct? I think I'm making it harder than it is?
Any thoughts?
You might be missing a couple of quotation marks.
$boatslip->rent_sale_or_both == "rent"
$boatslip->rent_sale_or_both == "sale"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have to evaluate the dynamic expressions and based on the conditions, I need to show the other div.
My expression is:
{ [appln.module.name.VALUE] == 1 && [appln.module.name.VALUE] != EFT }
In case both of these expressions satisfy conditions, then the div must be shown. The value will be calculated based on the changes made.
Could someone help on this, of how to parse and evaluate the conditions dynamically?
It sounds like the question boils down to "How do I show a DIV tag using PHP based on a conditional" To do this in PHP you could do something like the following...
<div id="YourDIV" <?php if ($ApplnModuleName != 1 || $EFT == 1){?>style="display:none"<?php } ?>>Your Content Goes Here</div>
The example above includes a negated implementation of your conditional. Both tests are required since $EFT could equal 1 which would need to hide the DIV.
An even better/cleaner way that would keep the contents of the DIV from being sent to the client would look like this...
<?php if ($ApplnModuleName == 1 && $EFT != 1) { ?>
<div id="YourDIV">Your Content Goes Here</div>
<?php } ?>
The former example would allow you to turn the DIV on using Javascript in the client. The later example would save you bandwidth and prevent potentially sensitive data from showing up in the source of the HTML in the client.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
It's a basic question, but I've googled all sorts of variations of it & nothing that quite answers me. I want to display one of two images. One if the criteria is met & one if it is not met. This code works. If criteria is met, it does display the image. But there is no alternative
<? if(stripslashes($getfeedbackQryRow['CompanyID'])=='344'){?><img src='img1.png' alt='Todays Bite'><? }?>
Then I put this together, but it's still wrong
<?PHP
if ($getfeedbackQryRow['CompanyID']) == '344') {
print ("<IMG SRC =/img1.png>");
}
else {
print ("<IMG SRC =img2.png>");
}
?>
This one looks like it should be right, but it throws an error... It's probably a syntax issue. Does anyone know what I'm doing wrong?
You have an extra ")"
if ($getfeedbackQryRow['CompanyID']) == '344') {
Remove the ")" here ['CompanyID'])
if ($getfeedbackQryRow['CompanyID']) == '344') {
// ^------- this is causing your error
You should do something simple like this:
$image_name = $getfeedbackQryRow['CompanyId'] == '344' ? 'img1.png' : 'img2.png';
echo '<img src="' . $image_name . '">';
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
First of all sorry for the most likely simple question. I have two echo statements from woocommerce that I need to subtract from each other.
the first is
<?php echo $woocommerce->cart->get_discounts_before_tax(); ?>
This gives me the amount of the coupon discount.
The second is
<?php echo $woocommerce->cart->get_cart_subtotal(); ?>
This gives me the total off all things in the cart.
I need to subtract the coupon discount from the cart subtotal. So I set this up
<?php
$first_number = $woocommerce->cart->get_cart_subtotal ;
$second_number = $woocommerce->cart->get_discounts_before_tax ;
$sum_total = $first_number - $second_number;
print ($sum_total);
?>
but obviously the syntax is not right and I just get 0. Please help me with some simple math!
I guess you've missed ()
$first_number = $woocommerce->cart->get_cart_subtotal();
$second_number = $woocommerce->cart->get_discounts_before_tax();
Without parentheses, you're trying to access a property; but not calling the existent method itself.
Obviously one or both of the function returns are non-integers or 0. Find the return of each and change it to the appropriate property or function. Try this public property for the first number.
$first_number = $woocommerce->cart->subtotal;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have in a foreach loop:
echo "<span style=\"" . myCss($value) . "\">lol</span>";
Which turns into (in source):
<span style="">lol</span>color: #999999;background-color: transparent;font-weight:normal;text-decoration: none;<span style="">...
Why? how to prevent the browser? Same for Chrome and Firefox. Note there is a reason for it being in-line, an I want to avoid doing it via javascript.
Try this
echo "<span style='" . myCss($value) . "'>lol</span>";
How about a little separation of PHP and HTML:
<span style="<?php echo myCss($value); ?>">lol</span>
Notice I encapsulate the PHP within the quotes, rather than echo the entire line. In a foreach loop it would look something like:
<?php
foreach($array as $key => $value){
?>
<span style="<?php echo myCss($value); ?>">lol</span>
<?php
}
?>
This separation of PHP and HTML has been the standard practice everywhere that I have worked, and I personally find it to be much more transparent.
Without seeing your function and the values of the variables, I an only assume that there are characters in the echoed result that mess up the html. You should always use htmlspecialschars() when you output to html:
echo "<span style=\"" . htmlspecialschars(myCss($value)) . "\">lol</span>";
Although you would probably use it in your function.