0

I am developing an application that should fetch data from mysql database to send sms. I'm decided to use cron job service to run a php script to fetch the data and send the sms after every 5 minutes.

My problem is I just can not figure out a way of setting up the select statement to NOT pick a record that had been picked earlier. That only fresh since the last run are selected and data is sent. Kindly, any one lead me please...

  //fetches fresh records
$sql = "SELECT name,amount, trans_id, msisdn, time_paid FROM customer ";


$result1 = mysqli_query($conn, $sql);
$resultarr = mysqli_fetch_assoc($result1); // fetch data from db

      get the variables from array
    $name = $resultarr['name'];
    $amount = $resultarr['amount'];
    $transaction_id = $resultarr['trans_id'];
    $date = $resultarr['time_paid'];

    // message template to be sent
    $message = "Dear $name we have received $amount from you. MPESA transaction Id $transaction_id on $date.";

      // requirements to send sms
    $mobilenumber = $resultarr['msisdn']; // get mobile number from array
    $message_sent = $message;

     //passing them as service arguments
    $serviceArguments = array(
            "mobilenumber" => $mobilenumber,
            "message" => $message_sent
    );

      //webservice to send sms
    $client = new SoapClient("http://50.33.64.16:8080/smsengine/smsws?WSDL");

    $result = $client->process($serviceArguments);

    return $result;

1 Answer 1

2

One possible idea could be to dump all processed record in a table(say tbl2) and Next time when you going to fetch records, Select all the record from primary table that don't exist in table tbl2.

SELECT t1.name
FROM table1 t1
LEFT JOIN table2 t2 ON t2.name = t1.name
WHERE t2.name IS NULL
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.