stublackett Posted July 15, 2008 Share Posted July 15, 2008 Hi, I'm constantly wondering the best way to format data pulled from a Database Table The DB Table field is set to "MEDIUMTEXT" The data is set out as an address would be so : <HOUSE NUMBER> <STREET> <TOWN / CITY> <POSTCODE> But when its pulled out of the Database it is set out like this HOUSE NUMBER STREET TOWN / CITY All on the same line How can I format this? Its probably best formatting it when the data is initially inserted I assume? When the data is inserted via a form it is set by a textbox, So when you press "enter" when inserting the data, That seems to have no play on whats inserted into the table I'm unsure wether this makes full sense, But if you dont understand what I'm asking I'll try explain it further Quote Link to comment Share on other sites More sharing options...
JD* Posted July 15, 2008 Share Posted July 15, 2008 If the text is being inserted into the database with line breaks, then when it comes back out just do: nl2br(return_query_string_here) That will take the new line character and turn it into a <br /> on the resulting page. Quote Link to comment Share on other sites More sharing options...
EKINdesigns Posted July 15, 2008 Share Posted July 15, 2008 I prefer to secure the information on insertion but format it when I extract it. I don't like having HTML code in my database. The nl2br() function is what you want though. Browsers don't display newlines. Using this function you convert new lines to break tags which the browser understands. Quote Link to comment Share on other sites More sharing options...
stublackett Posted July 15, 2008 Author Share Posted July 15, 2008 Cheers guys Just one question Where does that n12br go? My SQL Query stuff is here : <?php $id = $_GET['id']; $result = mysql_query("SELECT * FROM $db_table2 WHERE id='$_GET[id]'"); while($myrow = mysql_fetch_assoc($result)) I assume thats the bit were looking at? n12br($result) is possibly the answer, But if you could confirm please Quote Link to comment Share on other sites More sharing options...
revraz Posted July 15, 2008 Share Posted July 15, 2008 What is after your WHILE Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 15, 2008 Share Posted July 15, 2008 $id = $_GET['id']; $result = mysql_query("SELECT * FROM $db_table2 WHERE id='$_GET[id]'"); while($myrow = mysql_fetch_assoc($result)) echo nl2br( $myrow['col'] ); Quote Link to comment Share on other sites More sharing options...
stublackett Posted July 15, 2008 Author Share Posted July 15, 2008 The full code is : <?php $id = $_GET['id']; $result = mysql_query("SELECT * FROM $db_table2 WHERE id='$_GET[id]'"); while($myrow = mysql_fetch_assoc($result)) {//begin of loop $title = $myrow['title']; $address = $myrow['address']; $postcode = $myrow['postcode']; $telephone = $myrow['telephone']; $email = $myrow['email']; $website = $myrow['website']; $info = $myrow['info']; }//End While loop ?> Actually dont understand why I didnt put the full wack in Quote Link to comment Share on other sites More sharing options...
JD* Posted July 15, 2008 Share Posted July 15, 2008 You'd want echo nl2br($address)." <br />".$postcode Quote Link to comment Share on other sites More sharing options...
revraz Posted July 15, 2008 Share Posted July 15, 2008 Then it's alread formatted. Where are your echo lines? Easy enough to just do echo $title. "<br>"; echo $address. "<br>"; etc... 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.