PHP的语法while($ row = mysql_fetch_row ...?

时间:2013-08-20 20:28:07

标签: php mysql curl joomla

我正在尝试向多个收件人发送短信。我试图实现的代码是这样的: 我面临的问题是消息只传递给表中的第一条记录。

需要一些帮助,什么&我哪里错了?

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$result = mysql_query("SELECT name,mobile FROM members");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
while($row = mysql_fetch_row($result)) {
$mobile=$row[1];
$name=$row[0];

$request = "";
$param['mobileno'] = "91". $mobile;
$param['message']  = "Dear $name (organisation name) wishes you a very very Happy Birthday";
$param['username'] = "username";
$param['password']  = "password";
$param['sendername'] = "sender";
foreach ($param as $key => $val ){$request .= $key . "=" . urlencode($val);    
$request .= "&";}$request = substr( $request, 0, strlen( $request ) - 1 );
$url = "http://smsapi" . $request;
$ch = curl_init($url);curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
var_dump($result);exit;
curl_close( $ch );
}

1 个答案:

答案 0 :(得分:0)

您需要坚持使用Joomla编码标准。不要使用mysql_*函数,因为它们已被弃用并构成安全威胁。

$db = JFactory::getDbo();     
$query = $db->getQuery(true);    
$query->select('*')
->from('members');     
$db->setQuery($query);     
$rows = $db->loadObjectList();

while($rows){
    foreach ( $rows as $row ) {
        $mobile = $row->mobile;
        $name = $row->name;
    }

    //rest of code
}