Jump to content

text formatting in php / mysql


adam_gardner

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
Link to comment
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
Link to comment
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++;
}

?>
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.