0

大家好,我在'where子句'中不断得到一个未知列'Array' $receiverName,当我调试时$receiver我得到这个输出

array(
    (int) 0 => array(
        'Invoice' => array(
            'receiver_id' => '3',
            'id' => '1'
        ),
        'FieldsInvoice' => array(
            (int) 0 => array(
                'id' => '1',
                'field_id' => '9',
                'invoice_id' => '1',
                'entered_value' => '1000.00'
            )
        )
    ),
    (int) 1 => array(
        'Invoice' => array(
            'receiver_id' => '4',
            'id' => '2'
        ),
        'FieldsInvoice' => array(
            (int) 0 => array(
                'id' => '2',
                'field_id' => '9',
                'invoice_id' => '2',
                'entered_value' => '2000.00'
            )
        )
    ),
    (int) 2 => array(
        'Invoice' => array(
            'receiver_id' => '7',
            'id' => '3'
        ),
        'FieldsInvoice' => array()
    ),
    (int) 3 => array(
        'Invoice' => array(
            'receiver_id' => '8',
            'id' => '4'
        ),
        'FieldsInvoice' => array()
    ),

    //returns receiver_id from the invoices table where sender_id=current user account

$receiver=$this->Invoice->find('all',array(
        'fields'=>('receiver_id'),'conditions'=>array(
        'sender_id'=>$accounts2)));

    //returns company_name from the accounts tables where receiver_id=account.id

我想要做的是receiver_id从数组中抓取,然后将其与account.id然后打印进行比较,但它与我的findcompany_name中的 where 语句引发了问题$receiverName

$receiverName=$this->Account->find('all',array(
        'fields'=>('company_name'),'conditions'=>array(
        'id'=>$receiver)));
4

2 回答 2

1

那是因为您正在传递数组,请将您的 $receiver 行更改为以下

$receiver=$this->Invoice->field('receiver_id',array('sender_id'=>$accounts2));
于 2012-08-16T05:45:22.077 回答
-1

1) 下载并安装DebugKit(这是任何 CakePHP 项目的必备 - 认真)

2)点击右上角的DebugKit图标展开它的选项

3)点击“Sqllog”选项卡,看看它在哪里显示“Array”而不是你想要的值

4)将值更改为不是数组

5)给自己买一个冰淇淋或啤酒或其他什么,然后休息一晚,因为你的查询现在有效。


PS-也根据评论,应该是'fields'=>array('company_name'),不是'fields'=>('company_name')

于 2012-08-16T02:39:25.320 回答