好的,我尝试为我的数据库中的每个电话号码执行此代码。在遵循这里的建议之前我只能一次发送一个号码,我得到建议添加一个while语句来循环它。但是我的代码不再需要工作了。这是前后。我知道我做错了什么。
BEFORE(Working-no db)
// Set SMS options
$data['post'] = array (
'_rnr_se' => $rnrse,
'phoneNumber' => '123456789',
'text' => 'This is a test SMS',
'id' => ''
);
// Send the SMS
$response = xcurl::fetch('api.gateway.com/', $data);
// Evaluate the response
$value = json_decode($response['data']);
if($value->ok) {
echo "SMS message sent! ({$data['post']['phoneNumber']}: {$data['post']['text']})";
} else {
echo "Unable to send SMS! Error Code ({$value->data->code})\n\n";
echo 'data: '; print_r( $data); echo "\n\n";
echo 'response: '; print_r($response);
}
AFTER(不使用db)
// Set SMS options
mysql_connect("localhost", "music", "") or
die("Could not connect: " . mysql_error()); mysql_select_db("music");
$result = mysql_query("SELECT id, numbers FROM account_templates");
while ($row = mysql_fetch_array($result)) {
$data['post'] = array (
'_rnr_se' => $rnrse,
'phoneNumber' => $row['numbers'],
'text' => 'This is a test SMS',
'id' => ''
);
// Send the SMS
$response = xcurl::fetch('api.gateway.com', $data);
// Evaluate the response
$value = json_decode($response['data']);
}
if($value->ok) {
echo "SMS message sent! ({$data['post']['phoneNumber']}: {$data['post']['text']})";
} else {
echo "Unable to send SMS! Error Code ({$value->data->code})\n\n";
echo 'data: '; print_r( $data); echo "\n\n";
echo 'response: '; print_r($response);
}
答案 0 :(得分:0)
现在的方式是,发送过程正在通过while循环运行,但是检查是否发送了SMS的过程不是。
它可以像更改}
的位置一样简单。
拿走这个括号:
// Evaluate the response
$value = json_decode($response['data']);
} <------------------------------------------------ remove that one
并移动它
echo 'response: '; print_r($response);
}
} <------------------------------------------------add here