Page 1 of 1

how to insert an array into one field of any table

Posted: Tue Jun 22, 2010 12:28 am
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)"

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

Posted: Tue Jun 22, 2010 12:46 am
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.

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

Posted: Tue Jun 22, 2010 12:48 am
by mianmajidali
thanks alot dear, i m also trying to do this using implode() and explode()

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

Posted: Tue Jun 22, 2010 2:50 am
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.

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

Posted: Thu Jun 24, 2010 9:50 am
by mianmajidali
thanks of all colleagues, i have done this using implode and explode.