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
Share on other sites

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?)

Link to comment
Share on other sites

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

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.