Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.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
Php yii2:在多个条件下自动填充_Php_Mysql_Yii2 - Fatal编程技术网

Php yii2:在多个条件下自动填充

Php yii2:在多个条件下自动填充,php,mysql,yii2,Php,Mysql,Yii2,我的模型/表格如下: 餐桌室类别 id room_category 1 Classic 2 Deluxe 桌子房费 id room_category room_name room_charges 1 1 c1 600 2 2 d1 800 表ipd_费用 id doctor room_category charges_cash charges_cashless 1

我的模型/表格如下:

餐桌室类别

id room_category
1   Classic
2   Deluxe
桌子房费

id room_category room_name room_charges
1        1             c1       600
2        2             d1       800
表ipd_费用

id    doctor   room_category    charges_cash charges_cashless
1        1          1              200            300
2        1          2              300            400
表患者详细信息(患者入院)

表每日病房记录

id  patient_name  room_name(id)  doctor_name(id) charges ( from ipd_charges)
1          1           1           1              200
2          2           2           1              400
现在,医生的每日病房登记表中有一个下拉字段。当我选择下拉字段时,费用字段需要自动填充

我使用Jason和ajax通过以下代码实现了这一点,而没有考虑room_类别。但房间类别的费用各不相同。(这仅在保存记录后有效,我更喜欢在保存之前是否有办法提取费用。)

以下是我在控制器中的代码:

public function actionChargesCash($id){
        $model = \app\models\IpdCharges::findOne(['doctor'=>$id]);
        return \yii\helpers\Json::encode(['visit_charges'=>$model->charges_cash]); 
    }

    public function actionChargesCashLess($id){
        $model= \app\models\IpdCharges::findOne(['doctor'=>$id]);
        return \yii\helpers\Json::encode(['visit_charges'=>$model->charges_cashless]); 
    }
我也尝试过这个变量:

public function actionChargesCash($id){
        $model = \app\models\IpdCharges::find()
                ->where(['doctor'=>$id]) 
                 ->andwhere(['room_category'=>'daily_ward_entry.room_name'])->one();
如果我将
'daily\u ward\u entry.room\u name'
替换为room\u name id,如3或6,则得到结果,这意味着我没有使用正确的语法引用当前表中的列

如何在上述代码中包含房间名称的条件?
提前感谢您的宝贵帮助。

每日病房登记。如果没有任何关系或加入或子查询,房间名称将毫无意义。实际上,查询不知道
每日病房\u条目

建议:

1-创建关系并使用

2-在
room\u name=room\u category

3-创建一个带有子查询的查询,以在
中查找所有具有
房间类别的|一个IPD费用
,从每日病房条目中选择房间名称

以上所有建议都满足您的要求

另一个重要提示:

  • 和where()
    /
    或where()
    将where应用于默认条件
  • where()
    将忽略默认条件
我看不到任何默认条件(覆盖了
Find()
),因此,不需要使用
和where
,只需:

where(['doctor'=>$id,'room_category'=>3,...])

那就足够了

您所说的
每日病房\进入房间\房间名称
到底是什么意思<代码>每日病房记录。房间名称应替换为值。实际上,
daily\u ward\u entry.room\u name
完全没有意义。嗨,阿里,在表daily\u ward\u entry中有一列room\u name,我想将它与ipd\u charges room\u category中的room\u category进行比较,因为医生的费用随房间类别而变化Hi Ali-我也尝试了join,比如
$model=\app\models\IpdCharges::find()->innerjoin('daily_ward_entry'、'daily_ward_entry.room_name=ipd_charges.room_category')->where(['doctor'=>$id])->和where(['room_category'=>'daily_ward_entry.room_name')->one()但是我得到了一个空结果。我需要使用字段/列名来代替
=>3…
我该怎么做that@Pawan嗨,这里(['doctor'=>$id,'room_category'=>3,'Column'=>'value','Column'=>'value',…])亲爱的Ali-我真的觉得自己很笨,我不明白怎么用它,我想从当前表中提取数据,即
每日病房记录。房间名称
房间类别
进行比较亲爱的阿里-我会尝试你的其他建议,看看会发生什么。谢谢你的帮助。
where(['doctor'=>$id,'room_category'=>3,...])