looping thru array like for loop

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

looping thru array like for loop

Post by smilesmita »

hi,
i want to loop thru this array so that i can read the tagname from 0_filename and put records till 1_filename to insert query and again read from 1_filename to 2_filename and call query again and keep on doing that till the time i see the last n_filename tag

Code: Select all

Array(    
    [0_filename] => 070806_121635001first
    [0_statustype_code] => U
    [0_statustype_description] => Unreadfirst
    [0_manifest_shipper_name] => E-Z LINE PIPE SUPPORfirstT
    [0_manifest_shipper_shippernumber] => F6792Wfirst
    [0_manifest_shipper_address_addressline1] => 21340 HIGHWAY 6first
    [0_manifest_shipper_address_city] => MANVELfirst
    [0_manifest_shipper_address_stateprovincecode] => TXfirst
    [0_manifest_shipper_address_postalcode] => 77578-3832first
    [0_manifest_shipper_address_countrycode] => US
    [0_manifest_shipto_attentionname] => RON HANSONfirst
    [0_manifest_shipto_address_consigneename] => CENTERPOINT ENERGYfirst
    [0_manifest_shipto_address_addressline1] => 4011 TOWNSHIP LINE RDfirst
    [0_manifest_shipto_address_city] => POPLAR BLUFFfirst
    [0_manifest_shipto_address_stateprovincecode] => MOfirst
    [0_manifest_shipto_address_postalcode] => 63901first
    [0_manifest_shipto_address_countrycode] => USfirst
    [0_manifest_referencenumber_0_code] => JNfirst
    [0_manifest_referencenumber_0_value] => E-Z 707176first
    [0_manifest_referencenumber_1_code] => PNfirst
    [0_manifest_referencenumber_1_value] => 4502225369first
    [0_manifest_service_code] => 003first
    [0_manifest_pickupdate] => 20070806first
    [0_manifest_scheduleddeliverydate] => 20070809first
    [0_manifest_package_activity_date] => 20070806first
    [0_manifest_package_activity_time] => 113611first
    [0_manifest_package_trackingnumber] => 1ZF6792W0341116970first
    [0_manifest_package_referencenumber_0_code] => JNfirst
    [0_manifest_package_referencenumber_0_value] => E-Z 707176first
    [0_manifest_package_referencenumber_1_code] => PNfirst
    [0_manifest_package_referencenumber_1_value] => 4502225369first
    [0_manifest_billtoaccount_option] => 04first
    [0_manifest_billtoaccount_number] => W0783Xfirst
///till here it shud input all the above records where insert statement would look like this:
insert into table (0_filename,0_statustype_code.....till 0_manifest_billaccount_number) values(070.......,..,..,);
and now the loop shud start again from here.something like a for loop which goes on till it finds the last set of filename tag and its data beneath it.
    [1_filename] => 070806_073031001second
    [1_statustype_code] => U
    [1_statustype_description] => Unreadsecond
    [1_origin_packagereferencenumber_value] => 0012441second
    [1_origin_shipmentreferencenumber_value] => 0012second
    [1_origin_shippernumber] => 256YW5second
    [1_origin_trackingnumber] => 1Z256YW50341121213second
    [1_origin_date] => 20070806second
    [1_origin_time] => 042400second
    [1_origin_activitylocation_addressartifactformat_politicaldivision2] => SAINT PAULsecond
    [1_origin_activitylocation_addressartifactformat_politicaldivision1] => MNsecond
    [1_origin_activitylocation_addressartifactformat_countrycode] => USsecond
    [1_origin_billtoaccount_option] => 04second
    [1_origin_billtoaccount_number] => W0783Xsecond
    [1_origin_1_packagereferencenumber_value] => 01second
    [1_origin_1_shipmentreferencenumber_value] => 0441second
    [1_origin_1_shippernumber] => 256YW5second
    [1_origin_1_trackingnumber] => 1Z256YW50342133422second
    [1_origin_1_date] => 20070806second
    [1_origin_1_time] => 042400second
    [1_origin_1_activitylocation_addressartifactformat_politicaldivision2] => SAPAULsecond
    [1_origin_1_activitylocation_addressartifactformat_politicaldivision1] => Msecond
    [1_origin_1_activitylocation_addressartifactformat_countrycode] => USsecond
    [1_origin_1_billtoaccount_option] => 04second
    [1_origin_1_billtoaccount_number] => W0783Xsecond
Loop again from here:
    [2_filename] => 070806_073031001second
    [2_statustype_code] => U
    [2_statustype_description] => Unreadsecond
    [2_origin_packagereferencenumber_value] => 0012441second
    [2_origin_shipmentreferencenumber_value] => 0012second
    [2_origin_shippernumber] => 256YW5second
    [2_origin_trackingnumber] => 1Z256YW50341121213second
    [2_origin_date] => 20070806second
    [2_origin_time] => 042400second
    [2_origin_activitylocation_addressartifactformat_politicaldivision2] => SAINT PAULsecond
    [2_origin_activitylocation_addressartifactformat_politicaldivision1] => MNsecond
    [2_origin_activitylocation_addressartifactformat_countrycode] => USsecond
    [2_origin_billtoaccount_option] => 04second
    [2_origin_billtoaccount_number] => W0783Xsecond
    [2_origin_1_packagereferencenumber_value] => 01second
    [2_origin_1_shipmentreferencenumber_value] => 0441second
    [2_origin_1_shippernumber] => 256YW5second
    [2_origin_1_trackingnumber] => 1Z256YW50342133422second
    [2_origin_1_date] => 20070806second
    [2_origin_1_time] => 042400second
    [2_origin_1_activitylocation_addressartifactformat_politicaldivision2] => SAPAULsecond
    [2_origin_1_activitylocation_addressartifactformat_politicaldivision1] => Msecond
    [2_origin_1_activitylocation_addressartifactformat_countrycode] => USsecond
    [2_origin_1_billtoaccount_option] => 04second
    [2_origin_1_billtoaccount_number] => W0783Xsecond

)
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Code: Select all

foreach()
thewebdrivers
Forum Commoner
Posts: 41
Joined: Fri Aug 17, 2007 3:32 pm
Location: india
Contact:

Post by thewebdrivers »

you can probably use key, value pair traversing and check first 3 characters of the key, if they change you can fire a query thereafter.
Post Reply