Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...