我正在编写一个程序来通过XML API发送短信。我需要在单个XML Post中将相同的消息发送到多个数字以及不同的消息。我的脚本使用相同的消息向多个号码发送短消息,但无法添加不同的消息。mysql_fetch_row while循环没有得到所有行
我的表如下:
的MySQL> SELECT * FROM obox;
+----+-------+--------+------------+----------+-----+------------+----------+--------+-------+
| id | sid | sender | pick_time | del_time | ref | pno | msg | report | route |
+----+-------+--------+------------+----------+-----+------------+----------+--------+-------+
| 1 | 10000 | ALERTS | 1414478267 | 9 | 0 | 9XXXXXXXX | test sms | | 29 |
| 2 | 10000 | ALERTS | 1414478267 | 9 | 0 | 8XXXXXXXX | tesr sms | | 29 |
| 3 | 10000 | ALERTS | 1414478267 | 9 | 0 | 7XXXXXXXX | tesr sms | | 29 |
+----+-------+--------+------------+----------+-----+------------+----------+--------+-------+
我的脚本:
//geting msg
$content=mysql_query("select msg from obox where pick_time < '$t' and del_time < 100 group by msg", $db) or die(mysql_error());
//getting msg count
$num= mysql_num_rows($content);
//getting loop for each msg type
for($ctr=0; $ctr < $num; $ctr++){
$inctr=1;
while($row=mysql_fetch_row($content)){
$msg=$row[$ctr];
$xml_data ='<MESSAGE VER="1.2">'.
'<USER USERNAME="xxxxx" PASSWORD="xxxxx" DLR="0"/>';
//For each msg, get sender & pno
$result = mysql_query("select pno, sender from obox where msg='$msg' and pick_time < '$t' and del_time < 100", $db) or die(mysql_error());
$xml_data .= "<SMS TEXT='$msg' ID='$inctr'>";
$i= 1;
while($row1= mysql_fetch_row($result)){
$pno=$row1[0];
$sender=$row1[1];
$xml_data .= "<ADDRESS FROM='$sender' TO='91$pno' SEQ='$i'/>";
$i++;
}
$xml_data .= "</SMS>";
//歌厅MSG查询输出
的MySQL>从obox选择MSG其中pick_time < '1414748869' 和del_time < 100组由MSG
+----------+
| msg |
+----------+
| tesr sms |
| test sms |
+----------+
//脚本输出
<MESSAGE VER="1.2"><USER USERNAME="xxxx" PASSWORD="xxxx" DLR="0"/>
<SMS TEXT='test sms' ID='1'>
<ADDRESS FROM='ALERTS' TO='919xxxxxxxxx' SEQ='1'/></SMS>
</MESSAGE>
//输出应该
<MESSAGE VER="1.2"><USER USERNAME="xxxx" PASSWORD="xxxx" DLR="0"/>
<SMS TEXT='test sms' ID='1'>
<ADDRESS FROM='ALERTS' TO='919xxxxxxxxx' SEQ='1'/>
</SMS>
<SMS TEXT='tesr sms' ID='2'>
<ADDRESS FROM='ALERTS' TO='918xxxxxxxxx' SEQ='1'/>
<ADDRESS FROM='ALERTS' TO='917xxxxxxxxx' SEQ='2'/>
</SMS>
</MESSAGE>
请帮助。提前致谢。
问候
PB
注意,这mysql_ *库(http://php.net/ [是因为PHP 5.5(已废弃)手动/ EN/function.mysql-query.php)。考虑使用mysqli或pdo。 – 2014-10-31 14:07:06
停止!不要写另一行代码。 'mysql_ *'已被弃用,并且已经有一段时间了。再次使用其替换扩展名(PDO或mysqli_ *') – 2014-10-31 14:07:11