wordpress wpdb->update with post/request method NOT WORKING - php

I have to update records in database, but it's not working. Any ideas why?
$wpdb->update($table_name, array( 'value' => $request['promopunk_name']),"WHERE = 'name'");

change your query like.
$wpdb->update($table_name, array( 'value' => $request['promopunk_name']),array("name" => 'value'));
i hop this is used-full for you.

Related

Cakephp 2 update multiple records

i'm newbie in cakephp and i trying to update multiple rows in one transaction like:
$Model->saveMany($data, array('deep' => true));
... And the structure of the $data array is:
$data = array(
(int) 1 => array( 'Item' => array('id' => 2, 'name' => 'Name 1') ),
(int) 2 => array( 'Item' => array('id' => 3, 'name' => 'Name 2') ),
);
I Already tried with saveAll instruction and without deep parameter but nothing :( .... what's wrong?
Thanks for the help :)
The problem was that it had a required field in the validation that, although it was not compromised in the update, anyway it had to be passed in command
Thank you all!!
You can use this following code to insert data in Cake Php,
$this->request->data = Hash::insert($this->request->data);

Show $params array('{item}' =>…)

Need some help. Have this code in PaymentModule.php in Prestashop:
$params = array(
'{voucher_amount}' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'{voucher_num}' => $voucher->code,
'{firstname}' => $this->context->customer->firstname,
'{lastname}' => $this->context->customer->lastname,
'{id_order}' => $order->reference,
'{order_name}' => $order->getUniqReference()
);
I use $params['firstname'] for showing customer firstname and get nothing. I insert $params['firstname'] in /modules/bankwire/bankwire.php
Please tell me where I make a mistake?
Thanks
In your array you have a {firstname} key, but no firstname key.
If you want to get value, you should use: $params['{firstname}']
Try
$params = array(
'voucher_amount' => Tools::displayPrice($voucher->reduction_amount, $this->context->currency, false),
'voucher_num' => $voucher->code,
'firstname' => $this->context->customer->firstname,
'lastname' => $this->context->customer->lastname,
'id_order' => $order->reference,
'order_name' => $order->getUniqReference()
);
or in the case that volkerk is right, try
$params['{firstname}']
there is variables for email template, it's just assoc array, for access use
$params['{voucher_amount}']

insert and update at the same time with codeigniter

I have another problem again on querying in CodeIgniter,
I'll try to insert and update a "comment" on my website, but it's not working yet.
Here's my code :
on the Models (news_model.php)
public function simpan_komentar() {
$data = array(
'noid' => $_POST['noid'],
'kategori' => $_POST['kategori'],
'nama' => $_POST['nama'],
'pekerjaan' => $_POST['pekerjaan'],
'detail' => $_POST['detail'],
'created_at' => date('Y-m-d h:i:s'),
);
$data1 = array(
'komentar' => 'komentar + 1',
);
$this->db->insert('komentar',$data);
$this->db->update('news',$data1);
}
The insert query is working, but the update query didn't work
Can you tell me where's my fault?
Thanks
Try this
$this->db->set('komentar', 'komentar+1', FALSE);
//add your where condition if any
$this->db->update('news');

How to insert data from a single form to multiple tables in codeigniter framework ? - below method is not working

Anyone know how to insert data from a single form to multi tables in codeigniter
i tried below method but it is not working
Model
function add_models(){
$data1 = array(
'companykeyid' => $this->input->post('ckeyid'),
'name' => $this->input->post('name'),
'age' => $this->input->post('age'),
);
$data2 = array(
'companykeyid' => $this->input->post('ckeyid'),
'phrase' => $this->input->post('phrase'),
'medialength' => $this->input->post('medialength'),
);
$data3 = array(
'companykeyid' => $this->input->post('ckeyid'),
'phrase' => $this->input->post('phrase')
'medialength' => $this->input->post('medialength'),
);
$this->db->insert('girls', $data1);
$this->db->insert('movies',$data2);
$this->db->insert('keywords',$data3);
}
Method you made is, actually working, i think that your problem is syntax error you have (missing comma in data3 array).
So, this should work:
function add_models(){
$data1 = array(
'companykeyid' => $this->input->post('ckeyid'),
'name' => $this->input->post('name'),
'age' => $this->input->post('age')
);
$data2 = array(
'companykeyid' => $this->input->post('ckeyid'),
'phrase' => $this->input->post('phrase'),
'medialength' => $this->input->post('medialength')
);
$data3 = array(
'companykeyid' => $this->input->post('ckeyid'),
'phrase' => $this->input->post('phrase'),
'medialength' => $this->input->post('medialength')
);
$this->db->insert('girls', $data1);
$this->db->insert('movies',$data2);
$this->db->insert('keywords',$data3);
}
Important - you have to be sure that field names in tables are right... If this doesn't work, your problem is somewhere else in code (check your controller, view...)
In the array, you call the last value don't have "," get read of it and your model working correctly.
$data1 = array(
'companykeyid' => $this->input->post('ckeyid'),
'name' => $this->input->post('name'),
'age' => $this->input->post('age') <-----
);
In sinisake's answer shouldn't:
function add_models()
be chaged to:
function add_models($data)
Seems like there will be data to pass from the controller.

CakePHP paginate and order by

It feels like I've tried everything so I now come to you.
I am trying to order my data but it isn't going so well, kinda new to Cake.
This is my code:
$this->set('threads', $this->paginate('Thread', array(
'Thread.hidden' => 0,
'Thread.forum_category_id' => $id,
'order' => array(
'Thread.created' => 'desc'
)
)));
It generates an SQL error and this is the last and interesting part:
AND `Thread`.`forum_category_id` = 12 AND order = ('desc') ORDER BY `Thread`.`created` ASC LIMIT 25
How can I fix this? The field created obviously exists in the database. :/
You need to pass in the conditions key when using multiple filters (i.e. order, limit...). If you just specify conditions, you can pass it as second parameter directly.
This should do it:
$this->set('threads', $this->paginate('Thread', array(
'conditions' => array(
'Thread.hidden' => 0,
'Thread.forum_category_id' => $id
),
'order' => array(
'Thread.created' => 'desc'
)
)));
or perhaps a little clearer:
$this->paginate['order'] = array('Thread.created' => 'desc');
$this->paginate['conditions'] = array('Thread.hidden' => 0, ...);
$this->paginate['limit'] = 10;
$this->set('threads', $this->paginate());
if you get an error, add public $paginate; to the top of your controller.
Try
$this->set('threads', $this->paginate('Thread', array(
'Thread.hidden' => 0,
'Thread.forum_category_id' => $id
),
array(
'Thread.created' => 'desc'
)
));
I'm not a Cake master, just a guess.
EDIT. Yes, thats right. Cake manual excerpt:
Control which fields used for ordering
...
$this->paginate('Post', array(), array('title', 'slug'));
So order is the third argument.
try
$all_threads = $this->Threads->find('all',
array(
'order' => 'Threads.created'
)
);
$saida = $this->paginate($all_threads,[
'conditions' => ['Threads.hidden' => 0]
]);
There are a few things to take note of in paginate with order. For Cake 3.x, you need :
1) Ensure you have included the fields in 'sortWhitelist'
$this->paginate = [
'sortWhitelist' => [
'hidden', 'forum_category_id',
],
];
2) for 'order', if you put it under $this->paginate, you will not be able to sort that field in the view. So it is better to put the 'order' in the query (sadly this wasn't stated in the docs)
$query = $this->Thread->find()
->where( ['Thread.hidden' => 0, 'Thread.forum_category_id' => $id, ] )
->order( ['Thread.created' => 'desc'] );
$this->set('threads', $this->paginate($query)

Categories