Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
989 views
in Technique[技术] by (71.8m points)

html - PHP echo inside echo

I'm trying to call an HTML/PHP content that it's inside my database using:

<?php echo $row_content['conteudo']; ?>

When the row is called the HTML appears correctly but the PHP doesn't. I belieave it's cause of the echo inside the main echo.

<?php echo "
<h3>Hello</h3>
<?php do { ?>
  <div class="indios">
    <a href="indio.php?id=<?php echo $row_indiosct['id']; ?>">
      <img src="galeria/indios/<?php echo $row_indiosct['foto']; ?>" alt="<?php echo $row_indiosct['nome']; ?>" />
      <br /><?php echo $row_indiosct['nome']; ?></a></div>
  <?php } while ($row_indiosct = mysql_fetch_assoc($indiosct)); ?> "
 ?>

The line one of this code is the same echo as the first code field, it's not repeating, it's there just for help and to understand where is the problem.

I already fixed some quotation marks but it gives an error in the line of the 1st echo.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That is some of the ugliest code I have ever seen...

<?php 
echo '
<h3>Hello</h3>';

while ($row_indiosct = mysql_fetch_assoc($indiosct))
{
  echo '
    <div class="indios">
      <a href="indio.php?id='.$row_indiosct['id'].'">
        <img src="galeria/indios/'. $row_indiosct['foto'].'" alt="'.$row_indiosct['nome'].'" />
      <br />'.$row_indiosct['nome'].'</a>
    </div>';
} 
?>

You could also use the HEREDOC syntax.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...