Jump to content

Formatting Data pulled from a Database?


stublackett

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.