猿问

获取基于上个月的数据

我想根据上个月的 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,但这不起作用还有其他解决方案吗?


RISEBY
浏览 98回答 1
1回答

米脂

&nbsp; &nbsp;$id = $this->report_model->get_by_id($id);&nbsp; &nbsp; $price_now_query = $this->db->query("SELECT `price_now ` FROM `table_report` Where `date_report` IS BETWEEN (CURRENT_DATE() - INTERVAL 1 MONTH) AND CURRENT_DATE() AND `id_head_report`=$id");&nbsp; &nbsp; // CURRENT_DATE() - INTERVAL 1 MONTH - will get previous-month data&nbsp; &nbsp; $price_now = []&nbsp; &nbsp; if ($price_now_query && $price_now_query->num_rows() > 0) {&nbsp; &nbsp; &nbsp; &nbsp;$price_now = $price_now_query->row();&nbsp; &nbsp; }&nbsp; &nbsp; $row = $this->report_model->get_by_id($id);&nbsp; &nbsp; if ($row) {&nbsp; &nbsp; $data = array( 'button' => 'Update','action' =>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;site_url('controller_report/update_report'),&nbsp; &nbsp; &nbsp; 'id_report '&nbsp; &nbsp; &nbsp; => set_value('id_report ', $row->id_report ),&nbsp; &nbsp; &nbsp; 'id_head_report ' => set_value('id_head_report ', $row->id_head_report ),&nbsp; &nbsp; &nbsp; 'date_report'&nbsp; &nbsp; &nbsp;=> set_value('date_report', $row->date_report),&nbsp; &nbsp; &nbsp; 'price_now'&nbsp; &nbsp; &nbsp; &nbsp;=> set_value('price_now', $row->price_now),&nbsp; &nbsp; &nbsp; 'price_previous'&nbsp; => $price_previous,&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; );
随时随地看视频慕课网APP
我要回答