Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
I am confused as to why this piece of simple code is not displaying any data in either console.log or .actions class. There are no errors in console and I can see the correct value being returned in the payload window in inspector.
I would be grateful if someone could point out my error. Many thanks
<?php
$value = '10';
echo '<script>';
echo 'var value = ' . json_encode($value) . ';';
echo '$(".actions").text(value);';
echo 'console.log(value);';
echo '</script>';
?>
Make sure that jQuery is imported before your script, try this example.
<?php $value = '10';?>
<p class='actions'>Loading...</p>
<script src="jquery.min.js"></script>
<noscript>Javascript is disabled!</noscript>
<script>
$(function(){
var str = 'value = <?=$value?>';
$('.actions').text(str);
console.log(str);
});
</script>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 3 years ago.
Improve this question
"\t" is not working on my code
Tried to put a lot on .' '.
$name = '<h4 class="h4">NAME: '."\t".$firstname .' '. $midname .' '. $lastname. '</h4>';
Expected out put is
NAME: Mark stack
Put the Name: inside the <span>Name:</span> and set margin-right to the span to get your desired space.
echo $name = '<h4 class="h4"><span style = "margin-right: 20px;">NAME:</span> '.$firstname .' '. $midname .' '. $lastname. '</h4>';
Demo
html syntax cant read tab.... it dosent know it , as a charachter.
use this. <pre></pre>
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
I have a PHP file containing some variables and need to echo them multiple times in another file.
file1:
<?php
//some calculating going on
$var1 = 5;
$var2 = 2;
?>
file2:
<?php
echo $var1;
echo $var2;
?>
<?php
echo $var1;
echo $var2;
?>
How could this be achieved?
Your file2.php should include("file1.php"), like:
file2.php
<?php
include("file1.php");
echo $var1;
echo $var2;
?>
Assuming they're both in the same directory.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
i wanna test if my variable is empty or not to display some differents things.
When i don't use the else...if everything work but when i use this code :
<?php
$Amazon = get_post_meta($post->ID, "Lien Amazon", true);
?>
<?php
if( $Amazon != NULL ){
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
else {
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
?>
What is the problem ? Thank you
Here is an output error. You haven't closed and reopened the string on trying to concat a variable.
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;
Do instead:
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;
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
I get the following error and don't know where my mistake is:
Unexpected token <
Code (echo because of PHP used):
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append(';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td><a href='. $value2->itemToken .'>Edit</a></td></tr>';}
echo '});</script>';
The problem is that you do not have quotes "" surrounding your append (and href), and it is not being closed with );.
echo '<script type="text/javascript">
$(document).ready(function(){$("#sellerDrafts > tbody:last").append("';
foreach($this->view->sellercentral as $key2 => $value2)
{
echo '<tr><td>Edit</td></tr>';
}
echo '");});</script>';
On a side note, this is really not the best way to do this. A better way to do this would be to build it in PHP first then hand it off to your javascript. Like so:
<?php
$table = "";
foreach($this->view->sellercentral as $key2 => $value2)
{
$table = '<tr><td>Edit</td></tr>';
}
?>
<script type="text/javascript">
$(document).ready(function(){
$("#sellerDrafts > tbody:last").append("<?php echo $table; ?>");
});
</script>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
It's been a long time since I have done php so sorry for the silly question.
This is my current code, I'm trying to save the URL as a variable so that I can insert it into the echo, but it doesn't seem to work as nothing appears:
<?php ob_start();
echo get_post_meta($post->ID, 'oldurl', true);
$old_url = ob_get_contents();
ob_end_clean();
?>
<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
I have echoed $old_url and can see that it has the correct value, but how do I insert the value into the echo do_shortcode with url="$old_url"?
This doesn't work either:
<?php echo do_shortcode('[fbcomments][fbcomments url="echo $old_url;" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
You'll need to switch your quotes around. Single quotes print everything out as-is. Double-quotes will process the variables. Also, echo is not needed within an echo.
<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>
Another way to do it without switching your quotes is to break out of the statement:
<?php echo do_shortcode('[fbcomments][fbcomments url="'.$old_url.'" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Variables are not replaced in single quotes ...
<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Singles quotes doesn't allow variables parsing.
For example :
$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"
So you have to use double quotes or use the concatenate operator : .