Hello I want to get all the data from a table that are in the range of those arrays below : //A data sent from AJAX to PHP
$authors = $_POST['authors'];
$articles= $_POST['articles'];
The following cakePHP query is giving me the following errors :
Query:
$this->Mymodel->find('all', array('conditions' => array('Mymodel.name' => array($authors ,$articles)),'order'=>'Mymodel.id DESC'));
Error:
Notice (8): Array to string conversion [CORE/Cake/Model/Datasource/DboSource.php, line 2591]
Database Error
Error: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "," LINE 1: ...Mymodel" WHERE "Mymodel"."name" IN (Array, Array) ... ^
What am I doing wrong? I know that if I had an arry as $authors = array('sss','rrr');
it will work so why it does not in my case? Thank you in advance.
I believe your $authors
and $articles
variables are arrays already.
$this->Mymodel->find('all', array(
'conditions' => array(
'Mymodel.name' => array_merge($authors, $articles)
),
'order'=>'Mymodel.id DESC')
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.