Page 1 of 1

How to display multiple data that store in one fields?

Posted: Thu Nov 11, 2010 10:11 pm
by rolyestemonio
Hi guys i have something problem regarding displaying multiple data that store in one fields.
Is it possible to combine all the data in one fields and it will display separately?

Example:

I have 3 fields (id, description, link) and i store this in the ff. withe a separator "|":

description fields

This is a description1 | This is a description2 | This is a description3 | This is a description4

link fields

Link1 | Link2 | Link3 | Link4

And it will display like this :

1. This is a description1
Link1

2. This is a description2
Link2

3. This is a description3
Link3

4. This is a description4
Link 4

Thanks in advance to your help guys.

Re: How to display multiple data that store in one fields?

Posted: Thu Nov 11, 2010 10:33 pm
by dheeraja
Yes you can display data like that, you just have to use explode() like

Code: Select all

<?php
$result = explode("|", $row['description']);    //Variable name used by you.
?>
For more information refer below link..

http://php.net/manual/en/function.explode.php
http://www.w3schools.com/PHP/func_string_explode.asp

Re: How to display multiple data that store in one fields?

Posted: Thu Nov 11, 2010 10:39 pm
by califdon
While it is true that you can split (explode) a string into components, and you can separate data by regex expressions, but you should know that storing data this way violates the relational model that is the foundation of SQL. This means that if you are designing the database to begin with, you should avoid storing data in that way. It is called "repeating groups" and violates the second "normal form" defined by Dr. C. F. Codd, the IBM mathematician who developed the concept of relational databases in about 1970. When a database doesn't conform to the relational model, you will have difficulty using queries to retrieve data and may be unable to perform certain kinds of database queries at all. If you are stuck with data stored in this way, you may have no alternative than to split the strings, but forget about searches and so forth.

Re: How to display multiple data that store in one fields?

Posted: Sun Nov 14, 2010 8:18 pm
by rolyestemonio
Thanks. It really works.