0

Hi there im trying to update a nested array I have done some research and have come up with the following question but the answer isnt quite clear on how to update where x = this.

LINK How to updated nested array

$yourArray["experience"][1]["from"] = 2006;

That line looks like what I need but I need to figure out how to use the update part of it, this is my post script for my form.

$ID = $_POST["id"];
$NAMESTATE = $_POST["name"];
$REASON = $_POST["reason"];
require ('mongo.php');


if ($WISHNAMESTATE == "" and $ID == "")
{
    echo("OOPS SOMETHING WENT WRONG!");
    exit();
}
else
{
$m->update(array('_id' => $ID),(array('fields.NameState._0' => $NAMESTATE)));
   header("refresh:0;url=names_test.php"); 

My db looks like this.

array(
"_id"=>100000005,
"dclass"=>"Distributed",
    "fields"=>array(
"Name"=>array(
    "_0"=>"Testing",
),
"NameState"=>array(
    "_0"=>"PENDING",
),
 'setName': {
    '_0': 'test name'

So what this post needs to do is take the value NAMESTATE and update that field in the document with the matching ID, Please let me know if I am on the right track here.

1
  • I have done some more research and using this page stackoverflow.com/questions/10522347/… i have come up with this $m->update({'_id' : $ID , 'fields.NameState._0' : $NAMESTATE}); but Dreamweaver is giving me a syntax error Commented Nov 10, 2014 at 13:59

1 Answer 1

1

$_POST contains just String variables. If documents' _id field is Integer, you must be cast to int to $ID;

$m->update(array('_id' => (int) $ID),(array('fields.NameState._0' => $NAMESTATE)));
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.