0

I have the two columns in my table within Mysql. The Columns are Amount and NewObject which contains a serialized array structure like this:

{"type":"Sanction","data":{"MyID":-1,"Type":{"type":"Translation","data":{"code":"STATE","codeType":"Purchase"}},"Name":"newnamehereagain","Org":"60066","StartDate":"2012-02-15","EndDate":"2012-02-16","CloseDate":null,"EnteredDate":"2012-02-14 15:33:58","PacketSentDate":"2012-02-14 15:33:58","CancelledDate":null,"CancellationReason":null,"MyBigID":"004061","Countries":null,"SiteName":"nert","AddressLine1":"98 Patterson Road","AddressLine2":"","City":"Lawrenceville","State":"GA","Zip":"30044","Participants":null,"AdditionalInsured":"","Comments":null,"Program":"TT","Levels_SanctionLevel_array":"IT03,TLEVEL10"}}

The other column is amount. I am running this query to pull out all the rows that match the ID:

$sql2 = $db->query("SELECT `Amount`,`NewObject` FROM `mb_cart` WHERE `PersonID` = '$id'");

I then want to extract the 'Name' field from the serialized array NewObject (example: "Name":"newnamehereagain") and once I have the name, create an array with this name, and then add the 'Amount' from the database column to this name. Can this be accomplished?

Here is what I have attempted (no joy):

foreach ($sql2 as $values)
{
    $value = explode(",", $values);

foreach ($value as $v)
   {
   array($amount, $v);
   }
}

1 Answer 1

1

Your "NewObject" column appears to contain a nested hash which has been JSON-encoded. You should use json_decode to turn it back into a nested array structure, modify the value, and then reencode it via json_encode.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.