2014-10-31 67 views
-2

我正在编写一个程序来通过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

+0

注意,这mysql_ *库(http://php.net/ [是因为PHP 5.5(已废弃)手动/ EN/function.mysql-query.php)。考虑使用mysqli或pdo。 – 2014-10-31 14:07:06

+1

停止!不要写另一行代码。 'mysql_ *'已被弃用,并且已经有一段时间了。再次使用其替换扩展名(PDO或mysqli_ *') – 2014-10-31 14:07:11

回答

2

您的查询限制1。去掉它。

$content=mysql_query("select msg from obox where pick_time < '$t' and del_time < 100 group by msg", $db) or die(mysql_error()); 

编辑

您试图访问$行[1]当第二回路$ CTR = 1时,它应该只是$行[0];更改

$msg=$row[$ctr]; 

$msg=$row[0]; 

并删除for循环,如果你需要它。

EDIT2

你$ xml_data被覆盖在这条线上。

$xml_data ='<MESSAGE VER="1.2">'. 
'<USER USERNAME="xxxxx" PASSWORD="xxxxx" DLR="0"/>'; 

我之前的第一while循环初始化和

后串连它
$xml_data =''; 
while($row=mysql_fetch_row($content)){ 
. 
. 
. 
$xml_data .='<MESSAGE VER="1.2">'. 
'<USER USERNAME="xxxxx" PASSWORD="xxxxx" DLR="0"/>'; 
+0

已删除但仍然相同的问题 – user4124405 2014-10-31 14:16:24

+0

$ num是否等于1,2或3? – 2014-10-31 14:18:56

+0

不知道为什么$ num等于2时它应该是1,因为'测试短信'是唯一的结果,除非有一个隐藏的空间。 – 2014-10-31 14:30:08