Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.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 为每个唯一的支付id获取相同产品id的最后一行,并使用codeigniter更新不同表上的状态_Php_Mysql_Codeigniter_Subscription - Fatal编程技术网

Php 为每个唯一的支付id获取相同产品id的最后一行,并使用codeigniter更新不同表上的状态

Php 为每个唯一的支付id获取相同产品id的最后一行,并使用codeigniter更新不同表上的状态,php,mysql,codeigniter,subscription,Php,Mysql,Codeigniter,Subscription,我有两个表,第一个表叫做付款,见下文 我想获得最新的付款id,即每个产品id的最新付款,请参见突出显示的行,在本例中,我想获得10、9、8、3和6的产品id,但来自最新的付款id,即69、68、59、58和55 在我得到所有这些信息后,我想更新另一个名为list_data的表的状态,请参阅右侧: 此表的产品id与付款表中的产品id相同 我的总体目标是在付款后更新每个产品id的状态。 下面是我的控制器: $data["exp_date"] = $this->Superadmin_model_

我有两个表,第一个表叫做付款,见下文

我想获得最新的付款id,即每个产品id的最新付款,请参见突出显示的行,在本例中,我想获得10、9、8、3和6的产品id,但来自最新的付款id,即69、68、59、58和55

在我得到所有这些信息后,我想更新另一个名为list_data的表的状态,请参阅右侧:

此表的产品id与付款表中的产品id相同

我的总体目标是在付款后更新每个产品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);
                // }
            }
        }
在我的模型中,如果我不写limit 1,代码就不会得到最新的payment\u id,但是如果写limit 1,它只会得到1行product\u id和payment\u id


有人能帮我吗?谢谢

使用以下代码更新您的函数:

公共功能再次获取所需的所有详细信息{ $this->db->选择'py.payment\u id,py.user\u id,py.product\u id,py.txn\u id,py.payment\u gross,py.payer\u email,py.payment\u status,py.payment\u date,py.payment\u endDate,ld.ad\u status,ld.list\u data\u id'; $this->db->from'payments py'; $this->db->join'list\u data ld','py.product\u id=ld.list\u data\u id'; $this->db->group_by'py.product_id';//添加了此行 $this->db->order_by'py.payment_id'、'desc'; $query=$this->db->get; 如果$query->num\u rows>0{ 返回$query->result; }否则{ 返回数组; } }
您可以尝试使用子查询选择每个产品的最后一个付款\u id。首先,尝试如下修改模型:

公共功能再次获取所需的所有详细信息{ $this->db->选择'py.payment\u id,py.user\u id,py.product\u id,py.txn\u id,py.payment\u gross,py.payer\u email,py.payment\u status,py.payment\u date,py.payment\u endDate,ld.ad\u status,ld.list\u data\u id'; $this->db->from'payments py'; $this->db->where''payment\u id`在'payments'组中按'product\u id'选择MAX'payment\u id'; $this->db->join'list\u data ld','py.product\u id=ld.list\u data\u id'; $query=$this->db->get; 如果$query->num\u rows>0{ 返回$query->result; }否则{ 返回数组; } }
我认为你的代码解决了这个问题,但是在我确认之前,让我做更多的测试。谢谢你,如果你还在挣扎,明白吗
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;

}