我正在尝试将消息发送给今天生日的客户。 如果有 2 个客户生日,但它只向第一个客户发送两次 SMS。
我的 Controller 是这样的
$sms_count = $this->db->query("select * from tbl_customers where date_of_birth='". $today."' and concat('',phone * 1) = phone")->result();
$sender = $this->input->post($this->security->xss_clean('outlet_name'));
$message = $this->input->post($this->security->xss_clean('message'));
$numbers = array($this->db->query("select phone from tbl_customers where date_of_birth='". $today."'")->row('phone'));
foreach ($sms_count as $value) {
try {
$result = $textlocal->sendSms($numbers, $message, $sender);
$this->session->set_flashdata('exception', 'SMS has been sent successfully!');
}
}
最佳答案
首先获取所有数据,然后遍历这些数据并发送短信,如下所示
$this->db->select('phone');
$this->db->where('date_of_birth', $today);
$numbers = $this->db->get('tbl_customers')->result_array();
if($numbers){
foreach ($numbers as $key => $value) {
$result = $textlocal->sendSms($value['phone'], $message, $sender);
$this->session->set_flashdata('exception', 'SMS has been sent successfully!');
}
}
关于php - 在 codeigniter 中从数据库中选择手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57904437/