doushui3061 2015-09-05 12:22
浏览 17

多次发送短信

I have a problem on sending SMS using Ozeki Message Server. I want to send an sms multiple times, but it will only send when I reload the page manually.

Here's my code:

        <?php

    $balance = mysqli_query($connection, "SELECT * FROM balance WHERE status = 'Installment' OR status = 'No Downpayment' AND schoolyear = '$schoolyear'");
    $totalstud = mysqli_num_rows($balance);

    for($i=0; $i<$totalstud; $i++)
    {
      while($row_bal = mysqli_fetch_array($balance))
      {
        $student_id = $row_bal['student_id'];
        $outstanding_balance = $row_bal['outstanding_balance'];

        $student = mysqli_query($connection, "SELECT * FROM student WHERE student_id = '$student_id'");

        while($row_stud = mysqli_fetch_array($student))
        {
          $firstname = $row_stud['firstname'];
          $lastname = $row_stud['lastname'];
          $cp_num = $row_stud['cp_num'];

          $schedule = mysqli_query($connection, "SELECT * FROM schedule WHERE schoolyear = '$schoolyear'");

          while($row_sched = mysqli_fetch_array($schedule))
          {
            $date = $row_sched['date'];
            $time = $row_sched['time'];
            $message = $row_sched['message'];

            $message = $firstname . " " . $lastname . " " . $message . "" . $outstanding_balance . ".";

            echo "MESSAGE: " . $message . "<br><br>";
            $cp[$student_id] = $cp_num;
            $msg[$student_id] = $message;
          }
        }
      }
    }

    for($i=1; $i<=$totalstud; $i++)
    {
      $gatewayURL  =   'http://localhost:9333/ozeki?';
      $request = 'login=admin';
      $request .= '&password=abc123';
      $request .= '&action=sendMessage';
      $request .= '&messageType=SMS:TEXT';
      $request .= '&recepient='.urlencode($cp[$i]);
      $request .= '&messageData='.urlencode($msg[$i]);
      $request .= '&sender='.urlencode("OZEKI");

      $url =  $gatewayURL . $request;  

      //Open the URL to send the message
       file($url);

      if($i < $totalstud)
      {

      //This reloads page
      $page = $_SERVER['PHP_SELF'];
      $sec = "2";
    ?>
      <html>
          <head>
            <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
          </head>
          <body>
          <?php
              //echo "Watch the page reload itself in 10 second!";
          ?>
          </body>
      </html>
    <?php
      }
    }
    ?>

In my code I fetch data from my database. The $totalstud which counts the total number of students with Installment or No Downpayment. This will be the basis of how many times the SMS will be sent.

But what happen is, the message has been sent more than the $totalstud. Anyone knows how I can send the sms base from the $totalstud?

Assume that:

$totalstud = 3;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口