Hello so basically I am sending messages to different cell phone numbers in my table and my current code is:
您好基本上我正在向我的表中的不同手机号码发送消息,我当前的代码是:
<?php
require 'dbc.php';
$securimage = new Securimage();
include "smsGateway.php";
$smsGateway = new SmsGateway('email@gmail.com', 'pword');
$stmt = $dbc->query("SELECT * FROM tblcontactlist");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$message = "Hello world!";
$deviceID = 123;
$number = $row['contactNumber'];
$result = $smsGateway->sendMessageToNumber($number, $message, $deviceID);
}
?>
What I am doing is echoing every number and sending message to each of it.
我正在做的是回应每个号码并向每个号码发送信息。
What I wanted to do is to put all the cell phone numbers in an array and the code will look like this:
我想要做的是将所有手机号码放在一个数组中,代码如下所示:
$message = "Hello world!";
$deviceID = 123;
$numbers = ['+44771232343', '+44771232344'];
$result = $smsGateway->sendMessageToManyNumber($numbers, $message, $deviceID);
But instead of encoding every cell phone number into that array, I want to loop every number in my table and put the column values into that array.
但是我没有将每个手机号码编码到该阵列中,而是想循环我表格中的每个数字并将列值放入该数组中。
My table is named tblcontaclist
and the column name that contains the numbers is contactNumber
.
我的表名为tblcontaclist,包含数字的列名是contactNumber。
How can I achieve that?
我怎样才能做到这一点?
1 个解决方案
#1
$numbers = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$numbers[] = $row['contactNumber'];
}
$message = "Hello world!";
$deviceID = 123;
$result = $smsGateway->sendMessageToManyNumber($numbers, $message, $deviceID);
#1
$numbers = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$numbers[] = $row['contactNumber'];
}
$message = "Hello world!";
$deviceID = 123;
$result = $smsGateway->sendMessageToManyNumber($numbers, $message, $deviceID);