First time on here so I’ll try my best to provide as much info as possible. Also, my PHP knowledge is still not great so bear with my code.
Right now I have a foreach loop for a bunch of different sections of a XML file that I need to convert into an array and every other array is working as it should and outputting all of the specific data into the correct tables in the database.
foreach($branches as $branch_array){
connect($branch_array["url"] . '/property');
$property_list_xml = $request_refresh -> read_in_xml($url);
$properties = $request_refresh -> get_property_list($property_list_xml);
$property_details = array();
$property_paragraphs = array();
$property_files = array();
$property_bullets = array();
foreach($properties as $property_array){
connect($property_array["url"]);
$property_xml = $request_refresh -> read_in_xml($url);
print_r($property_xml);
$property_details[] = array(
"id"=> (string)$property_xml["id"],
"property_id"=> (string)$property_xml["propertyid"],
"firm_id"=>(string)$property_xml["firmid"],
"branch_id"=>(string)$property_xml["branchid"],
"featured"=>(string)$property_xml["featured"],
"name"=>(string)$property_xml->address->name,
"street"=>(string)$property_xml->address->street,
"locality"=>(string)$property_xml->address->locality,
"town"=>(string)$property_xml->address->town,
"county"=>(string)$property_xml->address->county,
"postcode"=>(string)$property_xml->address->postcode,
"custom_location"=>(string)$property_xml->address->custom_location,
"display"=>(string)$property_xml->address->display,
"price"=>(string)$property_xml->price,
"rental_fees"=>(string)$property_xml->rentalfees,
"lettings_fee"=>(string)$property_xml->lettingsfee,
"rm_qualifier"=>(string)$property_xml->rm_qualifier,
"available"=>(string)$property_xml->available,
"uploaded"=>(string)$property_xml->uploaded,
"longitude"=>(string)$property_xml->longitude,
"latitude"=>(string)$property_xml->latitude,
"web_status"=>(string)$property_xml->web_status,
"custom_status"=>(string)$property_xml->custom_status,
"type"=>(string)$property_xml->type,
"furnished"=>(string)$property_xml->furnished,
"rm_type"=>(string)$property_xml->rm_type,
"let_bond"=>(string)$property_xml->let_bond,
"rm_let_type_id"=>(string)$property_xml->rm_let_type_id,
"bedrooms"=>(string)$property_xml->bedrooms,
"receptions"=>(string)$property_xml->receptions,
"bathrooms"=>(string)$property_xml->bathrooms,
"userfield_1"=>(string)$property_xml->userfield_1,
"userfield_2"=>(string)$property_xml->userfield_2,
"sold_date"=>(string)$property_xml->sold_date,
"instructed"=>(string)$property_xml->instructed,
"let_date"=>(string)$property_xml->let_date,
"sold_price"=>(string)$property_xml->sold_price,
"garden"=>(string)$property_xml->garden,
"parking"=>(string)$property_xml->parking,
"new_build"=>(string)$property_xml->new_build,
"commission"=>(string)$property_xml->commission,
"tenure"=>(string)$property_xml->tenure,
"description"=>(string)$property_xml->description,
"energy_efficiency_current"=>(string)$property_xml->hip->energy_performance->energy_efficiency->current,
"energy_efficiency_potential"=>(string)$property_xml->hip->energy_performance->energy_efficiency->potential,
"environmental_impact_current"=>(string)$property_xml->hip->energy_performance->environmental_impact->current,
"environmental_impact_potential"=>(string)$property_xml->hip->energy_performance->environmental_impact->potential,
"council_tax_band"=>(string)$property_xml->council_tax->band,
);
if (isset($property_xml->bullets)){
foreach($property_xml->bullets[0] as $bullet){
$property_bullets[] = array(
"property_id"=> (string)$property_xml["propertyid"],
"bullet"=>(string)$bullet,
);
//print_r($bullet);
}
}
if (isset($property_xml->paragraphs)){
foreach($property_xml->paragraphs[0] as $paragraph){
//print_r($paragraph);
$property_paragraphs[] = array(
"property_id"=> (string)$property_xml["propertyid"],
"id"=> (string)$paragraph->attributes()->id,
"type"=>(string)$paragraph->attributes()->type,
"name"=>(string)$paragraph->name,
"file"=>(string)$paragraph->file,
"metric"=>(string)$paragraph->dimensions->metric,
"imperial"=>(string)$paragraph->dimensions->imperial,
"mixed"=>(string)$paragraph->dimensions->mixed,
"text"=>(string)$paragraph->text,
);
}
}
if (isset($property_xml->files)){
foreach($property_xml->files[0] as $files){
$property_files[] = array(
"property_id"=> (string)$property_xml["propertyid"],
"id"=> (string)$files->attributes()->id,
"file_type"=>(string)$files->attributes()->type,
"name"=>(string)$files->name,
"url"=>(string)$files->url,
"updated"=>(string)$files->updated,
);
}
}
}
//print_r($property_xml);
}
$five_arrays = array("branches"=> $branch_details,
"paragraphs"=> $property_paragraphs,
"properties"=> $property_details,
"bullets"=> $property_bullets,
"files"=> $property_files,
);
error_log("Connect to Database");
error_log("==================================================================");
$db_conn = $request_refresh -> connect_to_db($db_servername, $db_username, $db_password, $db_database);
error_log("Check Database connection is ok");
error_log("==================================================================");
$request_refresh -> check_db_connection_is_ok($db_conn);
error_log("Clear tables");
error_log("==================================================================");
$request_refresh -> clear_tables($table_names, $db_conn);
error_log("Add new records to tables");
error_log("==================================================================");
$failed_queries = $request_refresh -> add_new_records($db_conn, $table_names, $five_arrays);
The one giving me grief is the “bullet” since it gets all of the relevant data I require from the xml but then when it comes to getting it in the array, the second array element is the only one being uploaded to the table in the DB.
Array
(
[0] => Array
(
[property_id] => 2412
[bullet] => Modern Office Suites
)
[1] => Array
(
[property_id] => 2412
[bullet] => Lift
)
[2] => Array
(
[property_id] => 2412
[bullet] => Car Parking Space
)
[3] => Array
(
[property_id] => 3001
[bullet] => Luxury Lodge
)
[4] => Array
(
[property_id] => 3001
[bullet] => 2 Bedrooms
)
[5] => Array
(
[property_id] => 3001
[bullet] => Small Garden
)
[6] => Array
(
[property_id] => 3001
[bullet] => 2 Parking Spaces
)
[7] => Array
(
[property_id] => 3001
[bullet] => Viewing Highly Recommended
)
[8] => Array
(
[property_id] => 3051
[bullet] => 3 Bedrooms
)
[9] => Array
(
[property_id] => 3051
[bullet] => uPVC double glazing
)
[10] => Array
(
[property_id] => 3051
[bullet] => Gas fired central heating
)
[11] => Array
(
[property_id] => 3051
[bullet] => Parking
)
[12] => Array
(
[property_id] => 3051
[bullet] => Garden
)
[13] => Array
(
[property_id] => 3351
[bullet] => 3 Bedroom Cottage
)
[14] => Array
(
[property_id] => 3351
[bullet] => Central Heating
)
[15] => Array
(
[property_id] => 3351
[bullet] => Double Glazing
)
[16] => Array
(
[property_id] => 3351
[bullet] => Ideal First Time Buy
)
[17] => Array
(
[property_id] => 3146
[bullet] => 2 Bedrooms
)
[18] => Array
(
[property_id] => 3146
[bullet] => Attic Room
)
[19] => Array
(
[property_id] => 3146
[bullet] => uPVC double Glazing
)
[20] => Array
(
[property_id] => 3146
[bullet] => Gas Fired Central Heating
)
[21] => Array
(
[property_id] => 3146
[bullet] => Balcony enjoying views
)
[22] => Array
(
[property_id] => 3146
[bullet] => Viewing Recommended
)
[23] => Array
(
[property_id] => 3701
[bullet] => 2 Bedrooms
)
[24] => Array
(
[property_id] => 3701
[bullet] => Balcony
)
[25] => Array
(
[property_id] => 3701
[bullet] => Central Heating
)
[26] => Array
(
[property_id] => 3701
[bullet] => Parking Space
)
[27] => Array
(
[property_id] => 3701
[bullet] => Close to town centre
)
[28] => Array
(
[property_id] => 3701
[bullet] => Viewing Recommended
)
[29] => Array
(
[property_id] => 3265
[bullet] => 2 bedrooms
)
[30] => Array
(
[property_id] => 3265
[bullet] => Immaculately presented
)
[31] => Array
(
[property_id] => 3265
[bullet] => Courtyard Garden
)
[32] => Array
(
[property_id] => 3265
[bullet] => uPVC double glazing
)
[33] => Array
(
[property_id] => 3265
[bullet] => Viewing Recommended
)
[34] => Array
(
[property_id] => 1876
[bullet] => Stone built end of terrace cottage
)
[35] => Array
(
[property_id] => 1876
[bullet] => 3 Bedrooms
)
[36] => Array
(
[property_id] => 1876
[bullet] => Sympathetically improved & upgraded
)
[37] => Array
(
[property_id] => 1876
[bullet] => Original character features
)
[38] => Array
(
[property_id] => 1876
[bullet] => Recessed stone fireplaces
)
[39] => Array
(
[property_id] => 1876
[bullet] => Garden
)
[40] => Array
(
[property_id] => 1876
[bullet] => Views of Snowdonia
)
[41] => Array
(
[property_id] => 3541
[bullet] => 2 Bedroom
)
[42] => Array
(
[property_id] => 3541
[bullet] => Detached House
)
[43] => Array
(
[property_id] => 3541
[bullet] => Magical Setting
)
[44] => Array
(
[property_id] => 3541
[bullet] => Character Features
)
[45] => Array
(
[property_id] => 3541
[bullet] => Oil Fired Central Heating
)
[46] => Array
(
[property_id] => 3541
[bullet] => Double Glazing
)
[47] => Array
(
[property_id] => 3541
[bullet] => Viewing Recommended.
)
[48] => Array
(
[property_id] => 2270
[bullet] => Retail Premises
)
[49] => Array
(
[property_id] => 2270
[bullet] => 5 Self Contained Units
)
[50] => Array
(
[property_id] => 2270
[bullet] => Central Location
)
[51] => Array
(
[property_id] => 2270
[bullet] => Rear Access
)
[52] => Array
(
[property_id] => 2270
[bullet] => Small Parking Area
)
[53] => Array
(
[property_id] => 3190
[bullet] => Public House and Restaurant
)
[54] => Array
(
[property_id] => 3190
[bullet] => Set in Large Plot
)
[55] => Array
(
[property_id] => 3190
[bullet] => Parking
)
[56] => Array
(
[property_id] => 3190
[bullet] => Riverside Beer Garden
)
[57] => Array
(
[property_id] => 3190
[bullet] => 4 Bedroom Owners Accommodation
)
[58] => Array
(
[property_id] => 3190
[bullet] => Viewing Highly Recommended
)
[59] => Array
(
[property_id] => 814
[bullet] => Established B&B and Cafe
)
[60] => Array
(
[property_id] => 814
[bullet] => Popular village location
)
[61] => Array
(
[property_id] => 814
[bullet] => Snowdonia National Park
)
[62] => Array
(
[property_id] => 814
[bullet] => 5 letting rooms (3 En suite)
)
[63] => Array
(
[property_id] => 814
[bullet] => 4 owners bedrooms
)
[64] => Array
(
[property_id] => 814
[bullet] => Public car park
)
[65] => Array
(
[property_id] => 814
[bullet] => Going concern
)
)
Array
(
[0] => Array
(
[property_id] => 1632
[bullet] => Detached bungalow
)
[1] => Array
(
[property_id] => 1632
[bullet] => 4 Bedrooms
)
[2] => Array
(
[property_id] => 1632
[bullet] => Rural setting
)
[3] => Array
(
[property_id] => 1632
[bullet] => Views
)
[4] => Array
(
[property_id] => 1632
[bullet] => Gardens
)
)
It’s only up until 65 and then the second element is opened and this is the only one that is being uploaded.
This below is my expectation:
Array
(
[0] => Array
(
[property_id] => 2412
[bullet] => Modern Office Suites
)
[1] => Array
(
[property_id] => 2412
[bullet] => Lift
)
[2] => Array
(
[property_id] => 2412
[bullet] => Car Parking Space
)
[3] => Array
(
[property_id] => 3001
[bullet] => Luxury Lodge
)
[4] => Array
(
[property_id] => 3001
[bullet] => 2 Bedrooms
)
[5] => Array
(
[property_id] => 3001
[bullet] => Small Garden
)
[6] => Array
(
[property_id] => 3001
[bullet] => 2 Parking Spaces
)
[7] => Array
(
[property_id] => 3001
[bullet] => Viewing Highly Recommended
)
[8] => Array
(
[property_id] => 3051
[bullet] => 3 Bedrooms
)
[9] => Array
(
[property_id] => 3051
[bullet] => uPVC double glazing
)
[10] => Array
(
[property_id] => 3051
[bullet] => Gas fired central heating
)
[11] => Array
(
[property_id] => 3051
[bullet] => Parking
)
[12] => Array
(
[property_id] => 3051
[bullet] => Garden
)
[13] => Array
(
[property_id] => 3351
[bullet] => 3 Bedroom Cottage
)
[14] => Array
(
[property_id] => 3351
[bullet] => Central Heating
)
[15] => Array
(
[property_id] => 3351
[bullet] => Double Glazing
)
[16] => Array
(
[property_id] => 3351
[bullet] => Ideal First Time Buy
)
[17] => Array
(
[property_id] => 3146
[bullet] => 2 Bedrooms
)
[18] => Array
(
[property_id] => 3146
[bullet] => Attic Room
)
[19] => Array
(
[property_id] => 3146
[bullet] => uPVC double Glazing
)
[20] => Array
(
[property_id] => 3146
[bullet] => Gas Fired Central Heating
)
[21] => Array
(
[property_id] => 3146
[bullet] => Balcony enjoying views
)
[22] => Array
(
[property_id] => 3146
[bullet] => Viewing Recommended
)
[23] => Array
(
[property_id] => 3701
[bullet] => 2 Bedrooms
)
[24] => Array
(
[property_id] => 3701
[bullet] => Balcony
)
[25] => Array
(
[property_id] => 3701
[bullet] => Central Heating
)
[26] => Array
(
[property_id] => 3701
[bullet] => Parking Space
)
[27] => Array
(
[property_id] => 3701
[bullet] => Close to town centre
)
[28] => Array
(
[property_id] => 3701
[bullet] => Viewing Recommended
)
[29] => Array
(
[property_id] => 3265
[bullet] => 2 bedrooms
)
[30] => Array
(
[property_id] => 3265
[bullet] => Immaculately presented
)
[31] => Array
(
[property_id] => 3265
[bullet] => Courtyard Garden
)
[32] => Array
(
[property_id] => 3265
[bullet] => uPVC double glazing
)
[33] => Array
(
[property_id] => 3265
[bullet] => Viewing Recommended
)
[34] => Array
(
[property_id] => 1876
[bullet] => Stone built end of terrace cottage
)
[35] => Array
(
[property_id] => 1876
[bullet] => 3 Bedrooms
)
[36] => Array
(
[property_id] => 1876
[bullet] => Sympathetically improved & upgraded
)
[37] => Array
(
[property_id] => 1876
[bullet] => Original character features
)
[38] => Array
(
[property_id] => 1876
[bullet] => Recessed stone fireplaces
)
[39] => Array
(
[property_id] => 1876
[bullet] => Garden
)
[40] => Array
(
[property_id] => 1876
[bullet] => Views of Snowdonia
)
[41] => Array
(
[property_id] => 3541
[bullet] => 2 Bedroom
)
[42] => Array
(
[property_id] => 3541
[bullet] => Detached House
)
[43] => Array
(
[property_id] => 3541
[bullet] => Magical Setting
)
[44] => Array
(
[property_id] => 3541
[bullet] => Character Features
)
[45] => Array
(
[property_id] => 3541
[bullet] => Oil Fired Central Heating
)
[46] => Array
(
[property_id] => 3541
[bullet] => Double Glazing
)
[47] => Array
(
[property_id] => 3541
[bullet] => Viewing Recommended.
)
[48] => Array
(
[property_id] => 2270
[bullet] => Retail Premises
)
[49] => Array
(
[property_id] => 2270
[bullet] => 5 Self Contained Units
)
[50] => Array
(
[property_id] => 2270
[bullet] => Central Location
)
[51] => Array
(
[property_id] => 2270
[bullet] => Rear Access
)
[52] => Array
(
[property_id] => 2270
[bullet] => Small Parking Area
)
[53] => Array
(
[property_id] => 3190
[bullet] => Public House and Restaurant
)
[54] => Array
(
[property_id] => 3190
[bullet] => Set in Large Plot
)
[55] => Array
(
[property_id] => 3190
[bullet] => Parking
)
[56] => Array
(
[property_id] => 3190
[bullet] => Riverside Beer Garden
)
[57] => Array
(
[property_id] => 3190
[bullet] => 4 Bedroom Owners Accommodation
)
[58] => Array
(
[property_id] => 3190
[bullet] => Viewing Highly Recommended
)
[59] => Array
(
[property_id] => 814
[bullet] => Established B&B and Cafe
)
[60] => Array
(
[property_id] => 814
[bullet] => Popular village location
)
[61] => Array
(
[property_id] => 814
[bullet] => Snowdonia National Park
)
[62] => Array
(
[property_id] => 814
[bullet] => 5 letting rooms (3 En suite)
)
[63] => Array
(
[property_id] => 814
[bullet] => 4 owners bedrooms
)
[64] => Array
(
[property_id] => 814
[bullet] => Public car park
)
[65] => Array
(
[property_id] => 814
[bullet] => Going concern
)
[66] => Array
(
[property_id] => 1632
[bullet] => Detached bungalow
)
[67] => Array
(
[property_id] => 1632
[bullet] => 4 Bedrooms
)
[68] => Array
(
[property_id] => 1632
[bullet] => Rural setting
)
[69] => Array
(
[property_id] => 1632
[bullet] => Views
)
[70] => Array
(
[property_id] => 1632
[bullet] => Gardens
)
)
This is what I want since this will upload all of my data into the table. I just can’t understand why it’s only happening to this array and not the others since there all made the same way.