php Parsing From Stored Mysql comma seprated Data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adpkumar
Forum Newbie
Posts: 1
Joined: Tue Dec 15, 2009 5:53 am

php Parsing From Stored Mysql comma seprated Data

Post by adpkumar »

php Parsing From Stored Mysql comma seprated Data


like

id subject
1 science,maths
2 maths,english,science
3 history,maths


i want to display
science
maths
english
history

can u help me
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php Parsing From Stored Mysql comma seprated Data

Post by Christopher »

Use explode() see the manual.
(#10850)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php Parsing From Stored Mysql comma seprated Data

Post by AbraCadaver »

And array_unique():

Code: Select all

$result = array();
foreach ($row as $val) {
    $result = array_merge($result, explode(',', $val));
}
$result = array_unique($result);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply