我有两个表,第一个表称为payments
见下文
我想获取每个payment_id
中的最新product_id
(表示最新付款),请查看突出显示的行,在这种情况下,我希望获取product_id
中的10、9, 8、3和6,但最近的payment_id
是69、68、59、58和55。
获得所有这些信息后,我想在另一个名为list_data
的表上更新状态,请参见右图:
此表还product_id
表中有payments
个相同的产品ID。
总体而言,我的目标是在付款后更新每个product_id
的状态。
下面是我的控制器:
$data["exp_date"] = $this->Superadmin_model_CMS->get_all_detail_needed_again();
$this->load->helper('date');
foreach ($data["exp_date"] as $value) {
$exp_date = $value->payment_endDate;
$todays_date = date("Y-m-d");
$today = strtotime($todays_date);
$expiration_date = strtotime($exp_date);
if ($expiration_date <= $today && $value->ad_status === 'active') {
// if ($value->ad_status === 'active') {
$update_status = 'inactive';
$data = array('ad_status' => $update_status
);
$this->Listing_model->update_ads_status($value->list_data_id,$data);
// }
}
}
下面是我的模特
public function get_all_detail_needed_again() {
$this->db->select('py.payment_id,py.user_id,py.product_id,py.product_name,py.txn_id,py.payment_gross,py.payer_email,py.payment_status,py.payment_date,py.payment_endDate,ld.ad_status,ld.list_data_id');
$this->db->from('payments py');
$this->db->join('list_data ld','py.product_id = ld.list_data_id');
$this->db->order_by('py.payment_id','desc');
$this->db->limit(1); //If I don't put limit the code doesn't get the latest payment_id but if write limit 1,it only get 1 row of product_id and payment_id
$query = $this->db->get();
if($query->num_rows() > 0){
return $query->result();
} else{
return array();
}
}
public function update_ads_status($id,$data) {
$this->db->where('list_data_id',$id);
$this->db->update('list_data',$data);
return true;
}
在我的模型中,如果我没有写限制1,则代码不会获得最新的payment_id
,但是如果写限制1,则只能获得1行product_id
和{{1} }
有人可以帮助我吗?谢谢