Jump to content

problem with printing mysql output.


ts2000abc

Recommended Posts

I have a mysql query, the result is one long text line (line is just "text text text"; basicly word 'text' like 100 times).

Output goes to html table, like this:

<table border="1" width="140" cellpadding="0" cellspacing="0">
<tr>
<td width="140" nowrap="nowrap">
<!-- $text is the sql query result -->
<?php print $text; ?>
</td>
</tr>
</table>

 

now for some reason the result of the query comes out all in 1 line/row (like it is in database), like the nowrap isn't there...

 

but when i dont use mysql, text goes into rows just fine.

like this:

<table border="1" width="140" cellpadding="0" cellspacing="0">
<tr>
<td width="140" nowrap="nowrap">
<!-- $text is the sql query result -->
<?php 
$text = "text text text text text text text text text text text text text text text text text";
print $text; ?>
<!--ouput goes like:
text text text text text
text text text text text
-->
</td>
</tr>
</table>

 

question: should i format/modify the mysql output ($text) with some php function?

Link to comment
https://forums.phpfreaks.com/topic/80298-problem-with-printing-mysql-output/
Share on other sites

It is dependent on how you inputted the text.  Either way saying Nowrap="nowrap" will force no wrap on your text. 

If you have it 100 times you can't have a varchar type so then break lines ("\r\n") are carried in text and blob fields, so be observant of that

field type in database is "text", forgot to mention that

 

it actually does the same if use the nowrap or dont use it...

 

query result doesn't include br-tags or other kind of line formating. i'm trying to get the html to make the lines automaticly...

there is space in between the words but the html output is still all in one line.. (should it cut the lines when table width is limited and there is white space in between the words?)

this is just a test page. there is no css really...

 

i tried trim(), no luck...

and i tried to replace all the white spaces with   but str_replace() didn't find any, same thing with preg_replace.

 

wordwrap() code from php.net is the best solution so far... (gets the job done)

function utf8_wordwrap($str,$width=75,$break="<br />", $cut=true){
    return utf8_encode(wordwrap(utf8_decode($str), $width, $break, $cut));
}

print utf8_wordwrap($txt);

 

even though my page is using charset=iso-8859-1 and that code is for utf-8, but i think i'll just have change the charset of my page...

Archived

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

×
×
  • 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.