Jump to content

[SOLVED] Please help with this!!


rn14

Recommended Posts

Im trying to pass the values returned to the variable $to so that a message is sent to each number individualy but it only sends it to one number not them all

 

$query = "SELECT `mobile` FROM `customer`";

    $result = mysql_query($query) or die(mysql_error());

    $number = array();

    while(list($mobile) = mysql_fetch_row($result)) { $number[] = $mobile; }

 

    // Test it

    foreach($number as $mobile) { echo $mobile . "

"; }

 

 

 

 

 

$user = "xxxx";

$password = "";

$api_id = "";

$baseurl ="http://api.clickatell.com";

$text = $_POST['text'];

$to = $mobile;

 

 

Link to comment
Share on other sites

I need to loop through a database, take the phone number value, send an individual message to each number. This is my attempt. It only takes one number from the database insteading of looping through and sending a message to all the numbers.

 

$query = "SELECT `mobile` FROM `customer`";
    $result = mysql_query($query) or die(mysql_error());
    $number = array();
    while(list($mobile) = mysql_fetch_row($result)) { $number[] = $mobile; }

    // Test it
    foreach($number as $mobile) { echo $mobile . "
"; }

// These are the details for my clickatell account. the $to variable needs to be passed the phone numbers from database
$user = "xxxx";
$password = "";
$api_id = "";
$baseurl ="http://api.clickatell.com";
$text = $_POST['text'];
$to = $mobile; 




Link to comment
Share on other sites

Basically like this

 

<?php
// queries to retrieve the numbers, let's assume $row is holding the fetch array
// have your phone formatting here.  I don't know what it takes to send a sms (phone message), through
// php, so I can't help on that part
while ($row = mysql_fetch_array($query)) {
   // mail for each phone number here.
}
?>

Link to comment
Share on other sites

This is at least the third time you've asked this question today. The usual practice on this forum is to ask the question once and all the answers/replies will be in one place.

 

This section of code:

<?php
// These are the details for my clickatell account. the $to variable needs to be passed the phone numbers from database
$user = "xxxx";
$password = "";
$api_id = "";
$baseurl ="http://api.clickatell.com";
$text = $_POST['text'];
$to = $mobile;
?>

needs to be within the for loop.

 

Ken

Link to comment
Share on other sites

I meant to say "while" loop, not "for" loop.

<?php
$query = "SELECT mobile FROM customer";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {

// These are the details for my clickatell account. the $to variable needs to be passed the phone numbers from database
       $user = "xxxx";
       $password = "";
       $api_id = "";
       $baseurl ="http://api.clickatell.com";
       $text = $_POST['text'];
       $to = $row['mobile'];
}
?>

 

Ken

Link to comment
Share on other sites

Iv included the entire script probarly too much code. It will send a message but only too one number in the database not all the numbers in the database. I have included the form at the bottom where the person enters the message. Also in this you will see a text box where a number can be entered. This was because this script was initially meant to send to just an individual number.

 

<cfoutput>
<cfhttp url="http://api.clickatell.com/http/sendmsg" method="POST" resolveurl="false">
<cfhttpparam type="FORMFIELD" name="api_id" value="xxxxxxx">
<cfhttpparam type="FORMFIELD" name="user" value="xxxxxxx">
<cfhttpparam type="FORMFIELD" name="password" value="xxxxxxxxx">
<cfhttpparam type="FORMFIELD" name="text" value="<?$_POST['text'];?>">
<cfhttpparam type="FORMFIELD" name="to" value="">
</cfhttp>
</cfoutput>
PHP
<?
//dbconnection here

$query = "SELECT mobile FROM customer";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {

// These are the details for my clickatell account. the $to variable needs to be passed the phone numbers from database
       $user = "xxxx";
       $password = "xxxxx";
       $api_id = "xxxxx";
       $baseurl ="http://api.clickatell.com";
       $text = $_POST['text'];
       $to = $row['mobile'];
}
// auth call
$url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
$ret = file($url);
// split our response. return string is on first line of the data returned
$sess = split(":",$ret[0]);
if ($sess[0] == "OK") {
$sess_id = trim($sess[1]); // remove any whitespace
$url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
$ret = file($url);
$send = split(":",$ret[0]);
if ($send[0] == "ID")
echo "success<br>message ID: ". $send[1];
else
echo "send message failed";
} else {
echo "Authentication failure: ". $ret[0];
exit();
}
?>

 

<form action="page2.php" method="post">
To:<input type="Text" name="to"><br><br>
Message:<input type="text" name="text">
<br><br><input type="submit" value="send">
</form>

Link to comment
Share on other sites

You need to put all the code that deals with sending the message within the "while" loop or you will only send to the last number retrieved.

<?php
//dbconnection here

$query = "SELECT mobile FROM customer";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {

// These are the details for my clickatell account. the $to variable needs to be passed the phone numbers from database
       $user = "xxxx";
       $password = "xxxxx";
       $api_id = "xxxxx";
       $baseurl ="http://api.clickatell.com";
       $text = $_POST['text'];
       $to = $row['mobile'];
// auth call
       $url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id";
// do auth call
       $ret = file($url);
// split our response. return string is on first line of the data returned
       $sess = split(":",$ret[0]);
       if ($sess[0] == "OK") {
           $sess_id = trim($sess[1]); // remove any whitespace
           $url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$text";
// do sendmsg call
           $ret = file($url);
           $send = split(":",$ret[0]);
           if ($send[0] == "ID")
               echo "success<br>message ID: ". $send[1];
           else
               echo "send message failed for $to";
       } else
          exit("Authentication failure: ". $ret[0]);
}
?>

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.