Tell me, please, how to put another echo inside echo ? There is such a piece of code:

 while ($row = mysqli_fetch_array($select, MYSQLI_BOTH)){ echo "<div class=\"jumbotron\"></div>"; } 

Inside the div should be $row["id"] , but somehow it doesn't work out at all.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

In addition to the mentioned @cheops methods, you can also recall the printf function:

 while ($row = mysqli_fetch_array($select, MYSQLI_ASSOC)){ printf('<div class="jumbotron">%s</div>', $row['id']); } 

Comment:

In a good way, you should separate the view from the application logic. At first, PHP itself can be used as a template engine:

index.php

 <?php // ... Получаем некие данные из бд и помещаем результат в переменную $data $data = mysqli_fetch_all($select, MYSQLI_ASSOC); include "index.tpl.php" mysqli_free_result($select); mysqli_close($connection); 

index.tpl.php

 <?php foreach($data as $row): ?> <div class="jumbotron"><?= $row['id']; ?></div> <?php endforeach; ?> 

    In this case, they usually resort to interpolation of the array element

     while ($row = mysqli_fetch_array($select, MYSQLI_BOTH)){ echo "<div class=\"jumbotron\">{$row['id']}</div>"; } 

    It is also possible to concatenate strings using an operator.

     while ($row = mysqli_fetch_array($select, MYSQLI_BOTH)){ echo "<div class=\"jumbotron\">" . $row['id'] . "</div>"; } 

    Or a comma-separated list of output elements.

     while ($row = mysqli_fetch_array($select, MYSQLI_BOTH)){ echo "<div class=\"jumbotron\">" , $row['id'] , "</div>"; }