Db::name('report')->where(['inquiryid'=> $data['inquiry_id']])->value('id');用这种形式,输出 查询returnPrice表中create_time中最新的一条记录,并且inquiry_id相等
时间: 2024-01-25 22:02:36 浏览: 28
要查询`returnPrice`表中`create_time`最新的一条记录,并且`inquiry_id`相等,可以使用以下代码:
```php
$latestRecordId = Db::name('returnPrice')
->where('inquiry_id', $data['inquiry_id'])
->order('create_time', 'desc')
->value('id');
```
上述代码使用`Db::name('returnPrice')`指定要查询的表为`returnPrice`,`where`方法指定查询条件为`inquiry_id`等于`$data['inquiry_id']`,`order`方法按照`create_time`字段降序排列,最后使用`value`方法取出最新一条记录的`id`值。
请确保在使用前已经正确配置了数据库连接,并且已经引入了相应的命名空间和数据库类。
相关问题
$openid = $_GET["openid"]; $uid = $this->uid($openid); $uid = 1; $sql = "SELECT * FROM `data_user_item` where `uid` = $uid and `status` = 0"; $data_user_item = $this->app->db->query($sql); $data_news_item = array(); foreach ($data_user_item as $k => $v) { $item_id = $v["item_id"]; $sql = "SELECT * FROM `data_news_item` where `id` = $item_id"; //执行插入操作 $news_item = $this->app->db->query($sql); $data_news_item[$k] = $news_item[0]; }
这段代码的作用是从数据表 `data_user_item` 中查询指定用户的未使用的物品信息,并通过循环将每个物品对应的新闻信息从数据表 `data_news_item` 中查询出来,最终返回一个包含所有物品对应新闻信息的数组 `$data_news_item`。其中 `$openid` 是从 GET 请求中获取到的用户唯一标识,`$uid` 是通过 `$openid` 查询得到的用户 ID。需要注意的是,这段代码中 `$uid` 被硬编码为了 1,而非通过 `$openid` 查询得到的真实用户 ID,这可能是为了测试或者其他目的而做出的临时修改。
tp5 $yjdata=Db::name('patient')->where(['MobileNum'=>$request->param('MobileNum'),'cpid'=>$user['cpid']])->find(); if($yjdata){ $patientreport=$yjdata->patient_report; Db::name('patient')->where(['PatientNum'=>$yjdata['PatientNum']])->update($insertData); $patientreport->save($insertDatareport); }解决报错Trying to get property 'patient_report' of non-object
报错信息 "Trying to get property 'patient_report' of non-object" 提示你访问了一个非对象的属性,可能是在一个空对象上进行了属性访问。在你的代码中,$yjdata 是一个数组,而不是一个对象,所以无法通过 $yjdata->patient_report 来访问 patient_report 属性。
解决方法是将 $yjdata['patient_report'] 赋值给 $patientreport 变量,可以使用以下代码进行修改:
```
$yjdata = Db::name('patient')->where(['MobileNum'=>$request->param('MobileNum'), 'cpid'=>$user['cpid']])->find();
if ($yjdata) {
$patientreport = $yjdata['patient_report'];
Db::name('patient')->where(['PatientNum'=>$yjdata['PatientNum']])->update($insertData);
$patientreport->save($insertDatareport);
}
```
这样就可以避免报错了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)