亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在codeigniter中從數據庫中選擇電話

在codeigniter中從數據庫中選擇電話

PHP
慕的地8271018 2022-01-08 16:32:31
我正在嘗試將消息發送給今天過生日的客戶。如果 2 位客戶過生日,但它只向第一位客戶發送兩次短信。我的控制器就像$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!');                    }                 }
查看完整描述

2 回答

?
Helenr

TA貢獻1780條經驗 獲得超4個贊

首先獲取所有數據,然后遍歷該數據并發送短信如下


 $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!');


       }

   }


查看完整回答
反對 回復 2022-01-08
?
holdtom

TA貢獻1805條經驗 獲得超10個贊

在您的初始代碼中,您使用了 row(),這意味著您只得到一個數字,而不是一個數字數組。使用 result_array() 為您提供了一個關聯數組。


 $numbers = $this->db->select('phone')->get_where('date_of_birth', $today)->result_array();

 if(!empty($numbers)){

     foreach ($numbers as $key => $value) {

                 $result = $textlocal->sendSms($value['phone'], $message, $sender); 

                 $this->session->set_flashdata('exception', 'SMS has been sent successfully!');


       }

   } else {

                 var_dump($numbers);

                 $this->session->set_flashdata('exception', 'No Numbers found.');

}

如果 SMS 沒有發送,這應該足以幫助您調試代碼。


當您使用 foreach 循環時,無論數據是 1 還是更多,它都應該仍然有效。如果您在應用程序中運行此代碼,則需要應用時間邏輯并將 SMS 發送的結果保存到您的數據庫中。這樣它就不會意外地再次發送給該人,如果您將其作為 cron 作業運行,那么將其設置為每天一次就沒有問題。


查看完整回答
反對 回復 2022-01-08
  • 2 回答
  • 0 關注
  • 146 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號