php - 在 codeigniter 中从数据库中选择手机

标签 php mysql codeigniter

我正在尝试将消息发送给今天生日的客户。 如果有 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/

相关文章:

javascript - 从 Mysql 查询中获取 5 列及其值并转换为 PHP

php - 我如何制作像 Facebook 这样的照片库?

php - 使用带有codeigniter奇怪错误的sqlite

php - 通过 javascript 保存文件(到服务器)

php - Laravel验证不适用于多字节字符

php - 如何样式表

php - Laravel 在翻译字符串中使用翻译器

MySQL 事件调度程序每天在特定时间范围内运行

java - 提高大数据量插入速度

mysql - 将数据从 codeigniter 中的嵌入表单插入数据库