ts2000abc Posted December 5, 2007 Share Posted December 5, 2007 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 5, 2007 Share Posted December 5, 2007 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 Quote Link to comment Share on other sites More sharing options...
ts2000abc Posted December 5, 2007 Author Share Posted December 5, 2007 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?) Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 5, 2007 Share Posted December 5, 2007 well you can trim() the result, but its really its dependent on your css/xhtml formatting Quote Link to comment Share on other sites More sharing options...
ts2000abc Posted December 5, 2007 Author Share Posted December 5, 2007 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.