Jump to content

Archived

This topic is now archived and is closed to further replies.

adam_gardner

text formatting in php / mysql

Recommended Posts

hi guys,

I have a field set-up to store a users comments - like a message.

how can i get it to output again with the correct formatting they gave it? (i.e. line breaks etc.) because all my text just runs together

is it a php thing or a mysql formatting issue?

ps. my data appears as I typed it when viewed in phpmyadmin, but not when i echo it.

any help would be great!

thanks!

Adam

Share this post


Link to post
Share on other sites
[!--quoteo(post=362876:date=Apr 8 2006, 06:27 PM:name=adam_gardner)--][div class=\'quotetop\']QUOTE(adam_gardner @ Apr 8 2006, 06:27 PM) [snapback]362876[/snapback][/div][div class=\'quotemain\'][!--quotec--]
hi guys,

I have a field set-up to store a users comments - like a message.

how can i get it to output again with the correct formatting they gave it? (i.e. line breaks etc.) because all my text just runs together

is it a php thing or a mysql formatting issue?

ps. my data appears as I typed it when viewed in phpmyadmin, but not when i echo it.

any help would be great!

thanks!

Adam
[/quote]

umm not sure what you mean but try this

<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT message FROM inbox WHERE messageID = 'message id');
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
?>

and make it so its in a table and even with html variables like <center><br> etcc.. it should display properly

Share this post


Link to post
Share on other sites
[!--quoteo(post=362877:date=Apr 8 2006, 05:31 PM:name=desithugg)--][div class=\'quotetop\']QUOTE(desithugg @ Apr 8 2006, 05:31 PM) [snapback]362877[/snapback][/div][div class=\'quotemain\'][!--quotec--]
umm not sure what you mean but try this

<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tpf');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}
$result = mysql_query("SELECT message FROM inbox WHERE messageID = 'message id');
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);

echo $row[0]; // 42
?>

and make it so its in a table and even with html variables like <center><br> etcc.. it should display properly
[/quote]

nope, not sure you got me -- here's my php code

the problem is, like i'm doing in this post, putting line breaks everywhere, my text seems to run together.

here's the barebones of my php - very straight forward really.

<?
$query="SELECT * FROM messages WHERE toID = $CID";

$result=mysql_query($query) or die (mysql_error() . "\nActual query: " . $query);
$num=mysql_numrows($result);

echo "Inbox";

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

$Msg=mysql_result($result,$i,"message");

echo "Message :: $Msg";

$i++;
}

?>

Share this post


Link to post
Share on other sites
Line breaks in HTML are made by inserting the "<br />" tags, not by outputing a newline character. You can either output your text between "<pre>" and "</pre>" tags which preserve the new lines or use the function nl2br() on your output text:
[code]<?php echo 'Message :: ' . nl2br($Msg); ?>[/code] which places the "<br />" tag before each newline character.

Ken

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.