Array to DB

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
smilesmita
Forum Commoner
Posts: 30
Joined: Thu May 24, 2007 1:52 pm

Array to DB

Post by smilesmita »

hi there,

I have converted my xml string into array of this form.I wanted to know how i can put the array values and data into a database table...how shud i extract it.for example

SubscriptionFile is the column in my table and i want the value of it to get poplulated in the table.



Array
(
[SubscriptionFile] => xxxxxxxxxxxxxxx
[FileName] => xxxxxxxx1_1xxxxxxxx
[StatusType] => UUnread

Code: Select all

=> A
[Description] => Active
[Manifest] => Cxxxxxxxxxxxxx
4601 MACIE STCHARLOTTENC28217-1810US
CEHG4220 LAURA KOPPEHOUSTONTX770165029US

[Shipper] => xxxxxxxxxxxxxx
4601 MACIE STCHARLOTTENC28217-1810US

[ShipperNumber] => xxxxxxxxxx
[Address] => 4xxxxxxxxxxxx
[ShipTo] =>
Cxxxxxxxxxxx
[ConsigneeName] => xxxxxxxxxxx
[AddressLine1] => 4601 MACIE ST
[City] => CHARLOTTE
[StateProvinceCode] => NC
[PostalCode] => 28217-1810
[CountryCode] => US
[ReferenceNumber] => xxxxxxxxxxxxxx
[Service] => 003
[PickupDate] => 20070731
[ScheduledDeliveryDate] => 20070803
[Package] => xxxxxxxxxxxxxxx
[Activity] => xxxxxxxxxxxx
[Date] => 20070731
[Time] => 101300
[TrackingNumber] => 1xxxxx
[PackageServiceOptions] =>
[BillToAccount] => xxxxxxxxxxx
[Option] => xxxxxxxxxx
[Number] => xxxxxxxxxxx
[SubscriptionFile] => xxxxxxxxxxxxxxx
[FileName] => xxxxxxxx1_1xxxxxxxx
[StatusType] => UUnread

Code: Select all

=> A
[Description] => Active
[Manifest] => Cxxxxxxxxxxxxx
4601 MACIE STCHARLOTTENC28217-1810US
CEHG4220 LAURA KOPPEHOUSTONTX770165029US

[Shipper] => xxxxxxxxxxxxxx
4601 MACIE STCHARLOTTENC28217-1810US

[ShipperNumber] => xxxxxxxxxx
[Address] => 4xxxxxxxxxxxx
[ShipTo] =>
Cxxxxxxxxxxx
[ConsigneeName] => xxxxxxxxxxx
[AddressLine1] => 4601 MACIE ST
[City] => CHARLOTTE
[StateProvinceCode] => NC
[PostalCode] => 28217-1810
[CountryCode] => US
[ReferenceNumber] => xxxxxxxxxxxxxx
[Service] => 003
[PickupDate] => 20070731
[ScheduledDeliveryDate] => 20070803
[Package] => xxxxxxxxxxxxxxx
[Activity] => xxxxxxxxxxxx
[Date] => 20070731
[Time] => 101300
[TrackingNumber] => 1xxxxx
[PackageServiceOptions] =>
[BillToAccount] => xxxxxxxxxxx
[Option] => xxxxxxxxxx
[Number] => xxxxxxxxxxx)
)
User avatar
webgroundz
Forum Commoner
Posts: 58
Joined: Thu Jun 21, 2007 1:20 am
Location: Philippines

Post by webgroundz »

extract the array using for each then insert it into database

Code: Select all

foreach($array as $key => $values)
{
// Insert a row of information into the table "example"
mysql_query("INSERT INTO example 
(column1) VALUES('$values' ) ");
}
Last edited by webgroundz on Tue Jul 31, 2007 6:29 pm, edited 2 times in total.
User avatar
nathanr
Forum Contributor
Posts: 200
Joined: Wed Jun 07, 2006 5:46 pm

Post by nathanr »

Code: Select all

$arrayname['SubscriptionFile'];
this is how you reference the specific value in the array (where arrayname is the name of your array

and this is how you put in the database table (Assuming you know how to connect up to a database and run queries etc)

Code: Select all

$result = mysql_query("INSERT INTO table_name (SubscriptionFile) VALUES ('".$arrayname['SubscriptionFile']."')");
that is a very basic explanation, and assumes you know a bit of php; if yur not sure how to connect up to a db or the like, then you need to do some reading of the manual mate :)
Post Reply