Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在CakePHP中选择除一列以外的所有列?_Mysql_Cakephp - Fatal编程技术网

Mysql 在CakePHP中选择除一列以外的所有列?

Mysql 在CakePHP中选择除一列以外的所有列?,mysql,cakephp,Mysql,Cakephp,我有一个订单表,有30多列。我想显示我的订单表中除属性列以外的所有列 我们都知道,要从表中选择特定id的所有列,可以使用 $data = $this->Order->find('first', array('conditions'=>array('Order.id'=>1))); 您能告诉我如何用CakePHP 2.x编写查询吗?我怀疑您将该列从查询中排除会获得多少好处。如果确实需要执行此操作,则可以获取,然后从中删除列,然后通过定义查询返回的字段来使用find()中的

我有一个订单表,有30多列。我想显示我的
订单
表中除
属性
列以外的所有列

我们都知道,要从表中选择特定id的所有列,可以使用

$data = $this->Order->find('first', array('conditions'=>array('Order.id'=>1)));

您能告诉我如何用CakePHP 2.x编写查询吗?

我怀疑您将该列从查询中排除会获得多少好处。如果确实需要执行此操作,则可以获取,然后从中删除列,然后通过定义查询返回的字段来使用
find()
中的其余列:-

// Get the model’s schema.
$schema = $this->Order->schema();
// Remove the `attribute` column from the schema.
unset($schema['attribute']);
// Determine the remaining columns from the schema.
$cols = array_keys($schema);

// Now call your query specifying the fields you want back using the 
// columns we’ve just determined.
$data = $this->Order->find('first', 
    array(
        'fields' => $cols,
        'conditions' => array('Order.id' => 1)
    )
);
您应在此处使用:


好啊让我核对一下你的答案
$fields = array_keys($this->Order->getColumnTypes());  /* Returns an associative array of field names and column types*/
$key = array_search('attribute', $fields);             /* Search the key having attribute field */
unset($fields[$key]);         /* Remove the key value pair corresponding to attribute */
$this->Order->find('all', array('fields' => $fields));  /* Apply search specifying the fields */