How to give the content of $topic_image to a variable like this at the source part?
The problem is here: --> src="image/<?php echo $topi_image?>" .
$display_content=<<<END_OF_TEXT
<div>
<img src="image/<?php echo $topic_image ?>" style="width:200px;height:150px;">
<p style="float:left">$topic_pris</p>
<p style="float:left">$topic_title</p>
<p style="float:left">$topic_name</p>
</div>
END_OF_TEXT;
Heredoc expands variables itself. You don't need the whole <?php echo $topic_image ?>, just the variable:
$display_content=<<<END_OF_TEXT
<div>
<img src="image/${topic_image}" style="width:200px;height:150px;">
<p style="float:left">$topic_pris</p>
<p style="float:left">$topic_title</p>
<p style="float:left">$topic_name</p>
</div>
END_OF_TEXT;
Related
Issue
I'm currently attempting to create a "cell" for each mysql row similar to how twitter has it, but for some reason i'm logging
PHP Parse error: parse error, expecting `','' or `';''
Code
I'm fairly new to PHP I am unsure of why my code is creating this error.
<?php
while ($row = mysql_fetch_array($rs)) {
$unformatted = $row['mcap_HKD'];
$output = number_format($unformatted);
$time = time_elapsed_string($row['time']);
echo
"<div class="content">
<div class="headers">
<div class="info">
<strong class="scode">".$row['scode']."</strong><br>
<span class="sname">".$row['sname']."</span><br>
<span class="industry">".$row['main_industry']."</span>
</div>
<small class="time">."$time."</small>
</div>
<div class="news">
".$row['title']."
</div>
</div>";
}
I know that through testing that I am able to reach the server and that it will output the data just fine on its own, and even when i output single variables onto one div, but for some reason this is not working when i put extra divs like i do above. I have attempted to echo each line by itself but it still returns the same error.
Issue
PHP use " as a string delimiter (it has several string delimiters). When, in you echo statement, you are not escaping the ", it's as if you stop the string. So PHP is waiting for a string concatenation . or , or the ; end of statement character.
Resolution
You must escape " characters in you echo statement as such: \" ; it should look like:
Escape string delimiters
echo
"<div class=\"content\">
<div class=\"headers\">
<div class=\"info\">
<strong class=\"scode\">".$row['scode']."</strong><br>
<span class=\"sname\">".$row['sname']."</span><br>
<span class=\"industry\">".$row['main_industry']."</span>
</div>
<small class=\"time\">."$time."</small>
</div>
<div class=\"news\">
".$row['title']."
</div>
</div>";
Mix HTML and PHP
or do something like:
<?php while ($row = mysql_fetch_array($rs)): ?>
<?php
$unformatted = $row['mcap_HKD'];
$output = number_format($unformatted);
$time = time_elapsed_string($row['time']);
?>
<div class="content">
<div class="headers">
<div class="info">
<strong class="scode"><?= $row['scode']; ?></strong><br>
<span class="sname"><?= $row['sname']; ?></span><br>
<span class="industry"><?= $row['main_industry']; ?></span>
</div>
<small class="time"><?= $time; ?></small>
</div>
<div class="news">
<?= $row['title']; ?>
</div>
</div>
<?php endwhile; ?>
This has the benefit to not use PHP to print HTML tags, and with the <?= PHP opening tags, it's more readable!
I hope this helps you! :)
This error makes no sense. Here is the code block and my explanation below.
<?php foreach($rows as $value): ?>
<?php echo $value['authorname'] . "<br />\n";?>
<?php echo $value['title'] . "<br />\n";?>
<?php echo $value['rating'] . "<br />\n";?>
<?php echo $value['imagelocation'] . "<br />\n";?>
<div class="block">
<div class="row">
<div class="col-md-4 col-md-8">
<div class="widget-block">
<input id="rate1" value="<?php echo $value['rating'];?>" type="number" class="rating" data-max="5" data-min="0" data-size="sm" data-show-clear="false" readOnly="readOnly">
<img class="img-responsive wow fadeInLeftBig animated" data-wow-duration="1.5s" src=<?php echo $value['$imagelocation'];?> alt=<?php echo $value['$authorname'];?>>
<br>
Buy this book
</div>
</div>
<div class="col-md-6 col-md-8">
<div class="section-sub-title">
<article class="section-title-body white">
<h1 class="head-title">Author: <span><?php echo $value['$authorname'];?> -</span> <?php echo $value['$title'];?></h1>
<span class="point-line hidden-xs hidden-sm"></span>
<p>
<?php echo $value['$review'];?>
</p>
</article>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
The echo statements right after the start of the foreach loop prints out each variable fine. It isn't until we get down to the html that there are issues.
This code feeds an array of data from a DB then builds blocks of html code depending on the amount of data. In this case, I am pulling 8 records so this loop creates 8 copies of this code block. The thing that is frustrating is the variable "$rating" injects in all 8 blocks but none of the other variables do even though they print correctly on the page in the echo statements.
Maybe it is the data in the variable? For example as the code is parsed the first variable evaluated is $rating and works. The next one is the src property in the img tag $imagelocation and has an actual value of img\book_covers\TrueConviction.jpg
Are _ and . special characters and causing the issue? My return values would have _ . \ and spaces.
Thanks for any help.
I was right that it was the data IN the variables. The answer was urldecode. This solved my problems. I did this to all my variables.
$cleanauthorname = urldecode($value['authorname']);?>
I try to get data from text area,When submit form.
<?php
echo form_open_multipart('start/create','class="build_form"');
...
echo form_textarea('proDetail','','id="proDetail"');
...
echo form_submit('submit','Save','class="btn btn-primary"');
echo form_close();
?>
Try to show data in this function.
public function create()
{
echo print_r($this->input->post('proDetail'));
}
It give me a data from textarea, But it's not same when look in textarea.
How it look in textarea.
This is code in textarea.
<p><img class="fr-draggable fr-fir fr-dii" style="width: 300px;" src="http://localhost/siamfunding/img/users/upload/3a5e29ad7b5c64b16a97c56ce2a006cb7f66c7e3.jpg"></p>
<h1 style="text-align: center;">
<strong>asdasddadasdddd</strong>
</h1>
<p style="margin-left: 20px;">qwdqwdasdasasdwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</p>
<p style="">daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas</p>
<p style="">dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p style="">aaaaaaaaaaaaaaaad</p>
And, This is how it look when i try to show data.
This is code.
<p>
<img class="fr-draggable fr-fir fr-dii" xss="removed" src="http://localhost/siamfunding/img/users/upload/3a5e29ad7b5c64b16a97c56ce2a006cb7f66c7e3.jpg">
</p>
<h1 xss="removed">
<strong>asdasddadasdddd</strong>
</h1>
<p xss="removed">qwdqwdasdasasdwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</p>
<p xss="removed">daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas</p>
<p xss="removed">dddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</p>
<p xss="removed">aaaaaaaaaaaaaaaad</p>
<p xss="removed">
<br>
</p>
What happen, How can i make it look like in text area.
Ps.I try to import css and Jquery in page. It's not work.
Hello I have in my DB a column called capalivro that has my image paths.
I want to make the img src the content of that column, but I'm not succeding in doing this since I don't know how to put that PHP var in the HTML.
This way I tried doesn't work because the php doesn't work because of the quotation marks.
<?php while ($livro = mysql_fetch_assoc($livrotodos)) { ?>
<div class="large-2 columns">
<div class="livro">
<div class="livro-overlay">
<h3><?php echo $livro['nomelivro'] ?></h3>
</div>
<img src= "<?php $livro['capalivro']?>" />
</div>
</div>
<?php }
?>
</div>
<img src= "<?php $livro['capalivro']?>" />
</div>
should be:
</div>
<img src= <?php echo "\"". $livro['capalivro']."\""?> />
</div>
change your line containing the img src= bit to:
<img src="<?php echo $livro['capalivro']?>" />
without the echo part, it won't display the "string" from the database.
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 9 years ago.
Improve this question
i want to add li element to this page,
this website was done by someone else
the index.php file include several php files, along with them main.php.
this is the code for main.php
<div class="center"><p class="text3"><?php echo LABEL_TXT_FORNT_PAGE_TITLE;?></p>
<div class="netw"><div>
<div class="title"><?php echo LABEL_TXT_KDMATY;?></div></div>
<p><img src="img/<?php echo $dir;?>/1.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_KDAMATY;?> </p>
<p class="text2"></p>
</div>
<div class="suppserv"><div>
<div class="title"><?php echo LABEL_TXT_CHECK_PRINTING;?></div></div>
<p><img src="img/<?php echo $dir;?>/2.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_PRINT;?>
</p>
<p class="text2"></p></div>
<div class="remote"><div>
<div class="title"><?php echo LABEL_TXT_POINT_OF_SALES;?></div></div>
<p><img src="img/<?php echo $dir;?>/3.jpg" border='1' alt="img" /></p>
<p class="text1"><?php echo TXT_CONTANT_FOR_SALES;?></p>
<p class="text2"></p></div>
</div>
<div class="line"><img src="img/12.png" alt="img" /></div>
<div class="center2">
<div class="netw">
<p class="text4"><?php echo LABEL_TXT_EXPER;?></p>
<p class="text5"><?php echo TXT_CONTANT_EXPER;?></p>
<ul>
<li><?php echo UL_EXPER_EX1;?></li>
<li><?php echo UL_EXPER_EX2;?></li>
<li><?php echo UL_EXPER_EX3;?></li>
<li><?php echo UL_EXPER_EX4;?></li>
<li><?php echo UL_EXPER_EX5;?></li>
</ul>
<p class="text2"><a href="<?php echo SITE_URL; ?>/expertise.php"><?php echo
LABEL_TXT_MORE_LINKS;?><img alt="img" src="img/<?php echo $dir;?>/11.png"></a></p>
<div class="clear"></div>
</div>
<div class="remote">
<p class="text4"><?php echo LABEL_TXT_CUSTOMER;?></p>
<p class="text5"><?php echo TXT_CONTANT_CUSTOMER;?></p>
<ul>
<li><?php echo UL_CUSTOMER_EX1;?></li>
<li><?php echo UL_CUSTOMER_EX2;?></li>
<li><?php echo UL_CUSTOMER_EX3;?></li>
<li><?php echo UL_CUSTOMER_EX4;?></li>
<li><?php echo UL_CUSTOMER_EX5;?></li>
</ul>
</div>
<div class="suppserv">
<p class="text4"><?php echo LABEL_TXT_OUR_SERVICES;?></p>
<p class="text5"><?php echo TXT_CONTANT_SERVICES;?></p><br />
</div>
</div>
note this line :
<li><?php echo UL_CUSTOMER_EX1;?></li>
can someone explain to me what is this, it is not variable and not a constant, so what is it ?
You can define constants in php like this
define("MY_VARIABLE", 6)
And then access anywhere on the script:
echo MY_VARIABLE; // print 6
Is the same that LABEL_TXT_OUR_SERVICES
This is a constant, note that it hasn't the dollar sign before.
Refer to this http://php.net/manual/pt_BR/function.define.php
That constant was declared by using
define("UL_CUSTOMER_EX1", 'some_value_or_var');
Variables' first character is $ sign in PHP.
$var1 = 0; //this is a variable
define('CONST', 100); // is a constant
You can use $var1 and CONST in the page with one difference: $var1's value may be changed programatically but constansts no. Value of CONST cannot change during the execution of the script
That there is a constant. It must have been define()'d somewhere previously, possibly in an included file.
If I were you, I'd search for any define() statements that contain UL_CUSTOMER_EX1.
Yes, i agree with everybody else's opinion: it's a constant defined inside one of the included files.
BUT!
There might be another possibility, which may be probable if the original author is a novice developer:
an UNDEFINED constant, being treated as a string by default from php without warnings enabled.
Because, in PHP, if you use a constant which is undefined, it is reverted to a string which contains the constant name (eg: UNK_CONST becomes the string "UNK_CONST"). Of course it gives a warning too, but warnings may have been suppressed.