how to insert an array into one field of any table

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
mianmajidali
Forum Commoner
Posts: 30
Joined: Tue Dec 01, 2009 8:05 pm

how to insert an array into one field of any table

Post by mianmajidali »

hi to all,
i have created a table named as "content".... it has 4 columns "id", "page_name", "brows_title" and "content_title" . .
now i have an array of page names as

$pages=array("index.php","about.php","contact.php","laptop.php","printers.php");

now please tell me,how to insert this array into "content (page_name)"
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: how to insert an array into one field of any table

Post by cpetercarter »

You can serialize the array, and then place it in the database. When you retrieve information from the field, you can unserialize it to restore the original array.
mianmajidali
Forum Commoner
Posts: 30
Joined: Tue Dec 01, 2009 8:05 pm

Re: how to insert an array into one field of any table

Post by mianmajidali »

thanks alot dear, i m also trying to do this using implode() and explode()
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: how to insert an array into one field of any table

Post by rahulzatakia »

Hi,

you can use the following code for this..

Code: Select all

$pages=array("index.php","about.php","contact.php","laptop.php","printers.php");
$pages1 = implode(",",$pages);
and now you can use the $pages1 when inserting into database of "content (page_name)";
Similarly you can use the explode function when you want to retrieve it from the database.
mianmajidali
Forum Commoner
Posts: 30
Joined: Tue Dec 01, 2009 8:05 pm

Re: how to insert an array into one field of any table

Post by mianmajidali »

thanks of all colleagues, i have done this using implode and explode.
Post Reply