PDA

View Full Version : Getting text retrieved from mysql to fit tables properly


SSdraken
08-12-2005, 10:37 PM
Hey, I'm new here :)

I have been working on a really simple mysql/php set of pages.

Page 1: Input 3 peices of data (Title, Date and Text)

Page 2: Display all news that has been inputted

I have it working, except for one problem. My website is built with html, and tables. I want it so that when the text gets to the edge of the table, it drops down a line and starts again on the next line - so it doesn't carry on and on. Theres no problem with title and date - they're just a few words, but the text
part of the news is usually 5 or 6 lines long. This means that it wont all fit on one line without ruining the entire website display.

this is the current version i have running:

http://ssdraken.aspfreeserver.com/news.php

as you can see, everything is being pushed to the right because of the long
lines of text that are being displayed by my php code.


<?php

$username="username";
$password="password";
$database="draken";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news order by ID desc";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

echo "<br><br>";

$i=0;
while ($i < $num) {


$TITLE=mysql_result($result,$i,"TITLE");
$DATE=mysql_result($result,$i,"DATE");
$LINE1=mysql_result($result,$i,"LINE1");

echo "<b>$TITLE</b><br>$DATE<br><BR><i>$LINE1</i><br><br>";

$i++;
}

?>


this is the code that i'm running on the news display page. Can someone please fix my problem? I'm sure its incredibly easy I just don't know how to do it.

nikkiH
08-12-2005, 11:06 PM
Actually, it isn't that simple.
You have a huge long line of unbroken text. The browser doesn't know where to wrap it.
http://ssdraken.aspfreeserver.com/newsdisplay.phphttp://ssdraken.aspfre ...

You'd need to fix that. That has to be an error in the database (line1?).
No valid stuff to read would never have no spaces at all in it.

SSdraken
08-12-2005, 11:19 PM
thats something I did myself to try and get it to see what happens. i just copied and pasted what was in my clipboard a lot of times. Ideally I want a peice of code that creates a break every certain amount of characters, that I can input myself. Does it exist?

Or, when i'm inputting my data on the insert page (insert.php) can i type in <br> after every line and it will work when the text is displayed? I'll test that now ...

Kid Charming
08-13-2005, 12:14 AM
I'd use CSS for this instead of worrying about setting it in your database; let the browser set up line breaks.

SSdraken
08-13-2005, 12:35 PM
and how woudl I achieve that? Could you quickly run me through the process of doing it ... I know HTML and I know php enough to do this, but I'm not a huge code junkie :)