我想根据上个月的 id 或 id_head_report table_report 之前的行获取价格数据
+-----------------------------------------------------------------------+
| id_report | id_head_report | date_report | price_now | price_previous |
+-----------------------------------------------------------------------+
| 1 | 3 | 2019/01/30 | 55,000 | |
+-----------------------------------------------------------------------+
| 2 | 3 | 2019/02/29 | 1,000 | 55,000 |
+-----------------------------------------------------------------------+
| 3 | 4 | 2019/01/30 | 1,000 | |
+-----------------------------------------------------------------------+
| 4 | 4 | 2019/02/29 | 2,000 | |
+-----------------------------------------------------------------------+
控制器报告
$id = $this->report_model->get_by_id($id);
$price_now = $this->db->query("SELECT `price_now ` FROM `table_report` Where `date_report`=".date('M Y d', strtotime('-1 months'))." AND `id_head_report`=$id)->row();
$row = $this->report_model->get_by_id($id);
if ($row) {
$data = array( 'button' => 'Update','action' =>
site_url('controller_report/update_report'),
'id_report ' => set_value('id_report ', $row->id_report ),
'id_head_report ' => set_value('id_head_report ', $row->id_head_report ),
'date_report' => set_value('date_report', $row->date_report),
'price_now' => set_value('price_now', $row->price_now),
'price_previous' => $price_previous,
}
);
查看报告
<td align='right'>
<label for="decimal"><?php echo form_error('price_previous') ?></label>
<input style="background-color:#FFFF42" type="text" class="form-control" name="price_previous" id="price_previous" placeholder="price_previous" value="<?php echo $price_previous; ?>" />
</td>
更新价格上个月的 id,但这不起作用还有其他解决方案吗?
米脂