Web Hosting Talk







View Full Version : News System(Problem Viewing News)


sngskunk
12-10-2005, 07:10 PM
Okay so i created a news system, were i can psot news on my site and others can view it, but there is a problem. I will give you an example first.

Form Box (Begining)

Welcome to the site.

Enjoy your stay!

Form Box (End)

So I post that and it inserts it into my Mysql database. But, when i go to view it on my site it will show up like this.

News Show (Begin)

Welcome to the site. Enjoy your stay!

News Show (End)

Why did it not put in the line space, it just puts them together. So i go check my mysql table and in the table it inserted the space. But, when it come out on the site there is no space. Why?

If this helps to show the news i use this code.


<?php

include "db.php";

$query="SELECT * FROM site_news ORDER BY id DESC LIMIT 8";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {

$title=mysql_result($result,$i,"title");
$date=mysql_result($result,$i,"date");
$image=mysql_result($result,$i,"image");
$text=mysql_result($result,$i,"text");
$name=mysql_result($result,$i,"name");

//I changed below just to give you an idea, it is really a bunch over tables to give the right look
echo $title;
echo "<br>"
echo $text;

$i++;
}

?>


Help Please!!

AMSDallas
12-10-2005, 11:27 PM
It sounds like you need to enter the text into the form box as html. Separate lines with a <br> and it should display correctly.

sngskunk
12-11-2005, 02:27 AM
I dont not understand???

AMSDallas
12-11-2005, 02:31 AM
When you do the 'echo $text', the browser is interpreting it as html. Since there is no <br> in the contents of the $text variable, it's displaying it all on one line.

When you type the data into your form, it needs to look like this:

Welcome to the site.<br>
Enjoy your stay!

Burhan
12-11-2005, 05:40 AM
You need to do this.

echo nl2br($text)