$result = mysql_query("SELECT DISTINCT name, text FROM review order by id desc limit 3"); while ($row = mysql_fetch_assoc($result)) { ?> <h3><a title="title"><?php echo $row['name'] ?></a></h3> <p><?php echo $row['text'] ?></p> 

In this case, the text is an array, each element of which contains many different paragraphs that we get from the database and they are displayed sequentially. How to make a text output with line break observance?

  • $ result = mysql_query ("SELECT DISTINCT name, text FROM review order by id desc limit 3"); mysql_close (); while ($ row = mysql_fetch_assoc ($ result)) {?> <h3> <a title="title"> <? php echo $ row ['name']?>> ? php echo $ row ['text']?> </ p> - Dmitriy
  • what is this for comments? write the code in question, edit! - Dmitry Nail
  • What is the problem? <br> for line breaks - Mr. Black
  • $result = mysql_query("SELECT DISTINCT name, text FROM news order by id desc limit 3"); while ($row = mysql_fetch_assoc($result)) { $name = $row['name']; $text= $row['text']; echo " <h3><a title='title'>$name</a></h3> <p>$text</p><br> "; } $result = mysql_query("SELECT DISTINCT name, text FROM news order by id desc limit 3"); while ($row = mysql_fetch_assoc($result)) { $name = $row['name']; $text= $row['text']; echo " <h3><a title='title'>$name</a></h3> <p>$text</p><br> "; } - Mr. Black
  • Dmitry Nail the document was created with the full text of the code, after saving, I saw that the main part of the code is cut off and added it in the comments, if you give a link to the reason for this I will be grateful. Although in fact the answer to the question. - Dmitriy

1 answer 1

 $result = mysql_query("SELECT DISTINCT name, text FROM review order by id desc limit 3"); while ($row = mysql_fetch_assoc($result)) { $text = str_replace("\n","<br>",$row['text']); ?> <h3><a title="title"><?php echo $row['name'] ?></a></h3> <p><?php echo $text ?></p> 
  • Thank you very much. This cycle has completely solved the problem. - Dmitriy