Page 1 of 1

SQL DB/PHP Text/Data formatting

Posted: Sat Jan 16, 2010 5:57 am
by christh
Hi Guys

Whilst I'm sure this must have been covered, I'm failing to find anything on a search as, mainly I'm not too sure what to search for...

I have a new data base which I'm about to populate with data which will then be displayed in PHP.

My question is - what is the best practice to adopt when populating the database with data in regard to it's formatting or styling when it is displayed after a query?

To clarify...would I enter full html code along with the data into the database so it's displays correctly formated when required or would I enter data without html and format in PHP post a query?

For example, a field call "Title" could have the contents of -

<div align="center"><strong>A guide to php</strong></div>
or
"A guide to php" - with the Centering and Bold done in the script post data retrieval.

As a side note, if I was to use the first method would this cause issue if I was to use a free-text search option? -

ie the record would show on a search "A guide" but also show on a search "<div align>" or would sql/php ignore the html mark up when running a query?

I have a lot of data to enter into the database so want to make the correct choice now so as not to have to redo it at a later date when I employ a free text search.

I really hope the above makes sense - I've only been using php for 24 hours so am new to all this.

Many thanks in advance

Chris

Re: SQL DB/PHP Text/Data formatting

Posted: Sat Jan 16, 2010 10:22 am
by JakeJ
Find a tutorial on style sheets (CSS) and use those for formatting.

Putting code to format IN your database is really a bad idea because it seriously reduces the flexibility of your application among other reasons.

Always format in code unless there are very specific reasons to do otherwise.