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.
How to display multiple data that store in one fields?
Moderator: General Moderators
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to display multiple data that store in one fields?
Yes you can display data like that, you just have to use explode() like
For more information refer below link..
http://php.net/manual/en/function.explode.php
http://www.w3schools.com/PHP/func_string_explode.asp
Code: Select all
<?php
$result = explode("|", $row['description']); //Variable name used by you.
?>
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?
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.
-
rolyestemonio
- Forum Newbie
- Posts: 19
- Joined: Fri Jun 18, 2010 10:30 pm
- Location: Metro Manila - Paranaque City
- Contact:
Re: How to display multiple data that store in one fields?
Thanks. It really works.