I have a a loop that loops through data, what I am trying to achieve is for each loop an array is appended to another array before it is returned.
Here is what I have so far-
$response = array();
$response["CorrelationId"] = $correlationId;
This code sits outside the loop as I only want to return the "CorrelationId" once... This all works fine... for now I suppose!
foreach ($products as $value){
$pid = mysql_escape_string($value['ProductId']);
$dname = mysql_real_escape_string($value['departmentName']);
$cname = mysql_real_escape_string($value['categoryName']);
$pname = mysql_real_escape_string($value['productName']);
//Insert Product data into DB
$insert_product = "SQL Goes Here";
$insert_result = mysql_query($insert_product);
if(mysql_insert_id() > 0){
$response["Messages"] = array("$pid Has been added.");
}
}
return $response;
All that this is achieving so far is to add the last loop to the array. If I send 2 piecies of data to the loop, it will only have the last one in the array...
Am I missing something very basic here?
All I want if I where to send two pieces of data is to have the CorrelationId and 2 ["Messages"] returned.
Thanks