I have wordpress option_name student_data with option value a:7:{s:6:"status";s:1:"2";s:13:"name";s:73:"valuename";s:9:"address";s:32:"valueaddress";s:13:"school";s:32:"valueschool";s:4:"mother";s:270:"valuemother";s:12:"father";s:340:"valuefather";s:13:"total";s:131:"valuetotal";}
Below is my code to update the data, but it doesn't work.
$option_array = array(
'status' => '2',
'name' => 'valuename',
'address' => 'valueaddress',
'school' => 'valueschool',
'mother' => 'new_valuemother',
'father' => 'new_valuefather',
'total' => 'valuetotal'
);
update_option('student_data', $option_array);
Is there any solution? Thanks.
Related
I need some help with a JSON post request, I need to post an array of fields with multiple ids and values. Posting one id and value works but I can't figure out how to include multiple field IDs in this request.
Here is my code:
$appointment = $acuity->request('/appointments', array(
'method' => 'POST',
'data' => array(
'firstName' => 'Bob',
'lastName' => 'Burger',
'email' => 'bob#example.org',
'datetime' => '2016-04-26T19:00:00-0700',
'appointmentTypeID' => 5020,
'fields' => array(
array(
'id' => 4, // Custom field ID 4
'value' => '1600 Pennsylvania Avenue',
'id' => 5, // Custom field ID 5
'value' => '5550 Somewhere St.'
)
)
)
));
I suspect the intent is for this to use nested arrays, like so:
'fields' => array(
array(
'id' => 4, // Custom field ID 4
'value' => '1600 Pennsylvania Avenue',
),
array(
'id' => 5, // Custom field ID 5
'value' => '5550 Somewhere St.'
)
)
$data = array(
'id' => $id_product,
'qty' => 1,
'price' => '',
'name' => $name_group->name_product_groups.' '.$name_product->name_products,
'options' => array('player'=>$this->input->post('name'),'number'=>$this->input->post('number'),'size'=>$name_size->name_group.' '.$name_size->name_size,'comment'=>$this->input->post('comment')),
'id_groups' => $id_groups,
'fabric' => $name_fabric->name_fabrics,
'option' => $name_option,
'order_type' => 'Order Uniform');
$this->orders->insert_order_product_ready($data2);
can i ask, how to insert data on cart into database? because data has options
a possible return of a DB query looks like this:
array(
(int) 0 => array(
'Question' => array(
'id' => '737',
'question' => 'what is 1x7?',
),
'Answer' => array(
(int) 0 => array(
'id' => '2373',
'question_id' => '737',
'correct' => true,
'answer' => 'possible answer1',
'created' => '2014-05-08 13:46:43',
'modified' => '2014-05-08 13:46:43'
),
(int) 1 => array(
'id' => '2374',
'question_id' => '737',
'correct' => false,
'answer' => 'possible answer2',
'created' => '2014-05-08 13:46:43',
'modified' => '2014-05-08 13:46:43'
)
),
'Linkquestioncategory' => array(
(int) 0 => array(
'id' => '608',
'question_id' => '737',
'category_id' => '5',
'created' => '2014-05-08 13:46:47',
'modified' => '2014-05-08 13:46:47',
'Category' => array(
'id' => '5',
'name' => 'Simple Math',
'active' => true,
'linkquestioncategory_count' => '64',
'created' => '2014-02-03 09:20:54',
'modified' => '2014-03-04 14:47:05'
)
)
)
),
In order to clean it up to avoid sending to much unwanted data => my questions is => how can I get rid of those fields like
Answer.created
Linkquestioncategory.created
Linkquestioncategory.Category.created
I know that I can use conditions 'fields' to select the selected fields, but as far as I know, this works only for 'Question', but how can I manipulate those deeper array data?
Can I do this also with the 'fields' condition? If yes, how?
Thanks!!
http://nuts-and-bolts-of-cakephp.com/2008/09/05/example-of-cakephps-containable-for-deep-model-bindings/
This helped me a lot!!
Thanks!!
I'm using containable behavior and the result of my find('all') is:
array(
(int) 0 => array(
'User' => array(
'id' => '106',
'email' => 'daje#daje.it',
'pwd' => '0433c024cb08be13000d59a347e640482843f46f177e95749dc6599c259617fd3491dcb940b47693cbbc7f65a2cc5ef62deca2e600c1be133ad54170f7d1fbd1',
'role_id' => '3',
'active' => '1'
),
'Lead' => array(
'id' => '6'
),
'Estimate' => array(
(int) 0 => array(
'lead_id' => '6',
'Estimate' => array(
(int) 0 => array(
'TOT_count' => '2'
)
)
)
)
)
)
I need to to count how many estimates there are in the lead.
The total (2) is correct, but i see nested 'Estimated' array, why ?
The result i would like to get is:
array(
(int) 0 => array(
'User' => array(
'id' => '106',
'email' => 'daje#daje.it',
'pwd' => '0433c024cb08be13000d59a347e640482843f46f177e95749dc6599c259617fd3491dcb940b47693cbbc7f65a2cc5ef62deca2e600c1be133ad54170f7d1fbd1',
'role_id' => '3',
'active' => '1'
),
'Lead' => array(
'id' => '6'
),
'Estimate' => array(
'TOT_count' => '2'
)
)
)
This is the find:
$options = array(
'contain' => array(
'User',
'Estimate' => array(
'fields' => 'COUNT(*) AS TOT_count'
)
),
'conditions' => array('Lead.id' => 6),
'fields' => 'User.*',
'limit' => 1
);
debug($this->Lead->find('all', $options));
How can i do it?
Thanks!
When you use a "custom" AS statement, in your case TOT_count, Cake will always put this in a result key called 0. You can avoid this by defining TOT_count as a virtualField in your model. That way it will be nested directly under the model name in your resultset.
Secondly, the lead_id is forcedly retrieved, because it is "needed" to make the join with the Lead model. It can not properly retrieve all the data without that piece of information there.
not sure if this is the best way to do what I need but this is my issue. In my edit function view I recreate a forms fields based on what's in $this->data->expense but I need the array to be in a certain order or the fields get generated in the wrong order. This is the array I have:
'Expense' => array(
(int) 0 => array(
'id' => '98',
'date' => '2012-08-23',
'sitename' => '123',
'detail' => 'Breakfast',
'amount' => '100.00',
'miles' => null,
'total' => '100.00',
'expense_claim_id' => '63',
'created' => '2012-08-23 09:08:52',
'modified' => '2012-08-23 09:08:52',
'ExpenseClaim' => array(
'id' => '63',
'user_id' => '3',
'claim_status_id' => '1',
'created' => '2012-08-23 09:08:52',
'modified' => '2012-08-23 10:14:10',
'approved' => false,
'approved_by' => '0',
'date_submitted' => '2012-08-23 09:08:52'
),
'ExpenseCode' => array(
(int) 0 => array(
'id' => '1',
'name' => 'Plane fare',
'code' => '1',
'created' => '2012-07-31 09:52:02',
'modified' => '2012-07-31 09:53:57'
)
)
),
This is how I need it to be ordered (ExpenseCode) appears higher up:
'Expense' => array(
(int) 0 => array(
'id' => '98',
'date' => '2012-08-23',
'sitename' => '123',
'detail' => 'Breakfast',
'ExpenseCode' => array(
(int) 0 => array(
'id' => '1',
'name' => 'Plane fare',
'code' => '1',
'created' => '2012-07-31 09:52:02',
'modified' => '2012-07-31 09:53:57'
)
),
'amount' => '100.00',
'miles' => null,
'total' => '100.00',
'expense_claim_id' => '63',
'created' => '2012-08-23 09:08:52',
'modified' => '2012-08-23 09:08:52',
'ExpenseClaim' => array(
'id' => '63',
'user_id' => '3',
'claim_status_id' => '1',
'created' => '2012-08-23 09:08:52',
'modified' => '2012-08-23 10:14:10',
'approved' => false,
'approved_by' => '0',
'date_submitted' => '2012-08-23 09:08:52'
)
),
How can I achieve this and will changing the structure of it affect cake when I post?
As far as I know, there is no built-in function on CakePHP to custom sort an array. I guess you will have to do this with pure PHP. https://stackoverflow.com/search?q=custom+sort+array+php
Unless you must have the fields created dynamically, I suggest you to add each field yourself.
will changing the structure of it affect cake when I post?
No, if you simply put the fields in a different order this won't affect CakePHP. The data sent via POST will be in array $this->data['Expense']. When saving the data with $this->model->save(), the order does not matter.
This makes no sense. If the order of the data in an associative array is causing your HTML fields/form inputs..whatever to be in the wrong order, you're doing it wrong.
Try using the keys instead of just looping through in order. Or read more about associative arrays - there are a lot of fun / easy things to do to use & manipulate their data... but again to reiterate, there is NO need to return the data in a specific order.
Edit:
You could always create an array of keys and repeat through those. Might be a cleaner way of managing the order.