I'm trying to work out how I can break up a large block of text with CSS or PHP into paragraphs or line breaks. My PHP script queries a MYSQL database and returns a random number of entries (sentences) depending on the number selected by user. The results are echoed out in one large paragraph.
Is there anyway I can break up this one paragraph into smaller paragraphs? I don't want a line break after each result.
I can do this with fixed text in HTML with <p> tags or <br> tags but how can I do it with dynamically generated results when I have no idea how long the block of text will be? I'm quite new to PHP. Any suggestions appreciated.
Here is the code:
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="db"; // Database name
$tbl_name="sentence"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sn=$_POST['numberofsentences'];
$query="SELECT line FROM `sentence` ORDER BY rand() LIMIT $sn";
$result = mysql_query($query);
while ( $row = mysql_fetch_array($result) ) {
// do something with $row. The following echos the results and adds a space after each sentence.
echo $row['line'], " ";
}
// Close the database connection
mysql_close();
?>