0

I am retriving following data from the database.When I do print_r, it gives me follwing result.

Array ( [0] => stdClass Object ( [params] => {"size":"980|*|485|*|1","responsive":"1|*|0","align":"normal","autoplay":"1|*|6000" } ) )

Now I want to change the value of autoplay(which is last in this array) in it.How can I do that with the update query ?

NOTE: Field name is param in database and table name is xyz.

3
  • Question: What have you tried? Commented Nov 3, 2014 at 5:37
  • Because json_decode($array[0]->params) would get you the object that would allow you to modify it. Commented Nov 3, 2014 at 5:38
  • Actually I am totally newbie so I don't have any Idea how can I even start.If any help from you would be highly appreciated. Commented Nov 3, 2014 at 5:39

1 Answer 1

2

As stated, your params is a json object. You need to decode that object so that you can use it.

$data = json_decode($item[0]->params);

$data->autoplay = 'New VALUE';

Example

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

3 Comments

It worked like charm :) But can you tell me how can I update it in Database also ?? Will it be done by simple query like Update $tablename SET autoplay = $data->autoplay ??
I have tried thi query $myupdate = "update wp_nextend_smartslider_sliders set params = $data where id='3'"; but it gives me this error Object of class stdClass could not be converted to string in How can I pass string to this ?
$myupdate = "update wp_nextend_smartslider_sliders set params = '".json_encode($data)."' where id='3'"; would probably work.

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.