rn14 Posted February 21, 2007 Share Posted February 21, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/ Share on other sites More sharing options...
Ninjakreborn Posted February 21, 2007 Share Posted February 21, 2007 Please rephrase the question, it is not very easily understandable. Please also put all relevant code in code blocks so it's easier to discern using phpfreaks syntax highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190657 Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190672 Share on other sites More sharing options...
Ninjakreborn Posted February 21, 2007 Share Posted February 21, 2007 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. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190725 Share on other sites More sharing options...
kenrbnsn Posted February 21, 2007 Share Posted February 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190732 Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 Im sorry about that but just really need to get this working. Any chance you could help me put this into the for loop? Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190736 Share on other sites More sharing options...
kenrbnsn Posted February 21, 2007 Share Posted February 21, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190754 Share on other sites More sharing options...
rn14 Posted February 21, 2007 Author Share Posted February 21, 2007 This still only sends it too one number. Driving me mad! Any other suggestions? Thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190773 Share on other sites More sharing options...
kenrbnsn Posted February 21, 2007 Share Posted February 21, 2007 What code is after the "while" loop, since I don't see code sending anything. Ken Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190828 Share on other sites More sharing options...
rn14 Posted February 22, 2007 Author Share Posted February 22, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190893 Share on other sites More sharing options...
kenrbnsn Posted February 22, 2007 Share Posted February 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190905 Share on other sites More sharing options...
rn14 Posted February 22, 2007 Author Share Posted February 22, 2007 That worked a treat! Thanks boy! Quote Link to comment https://forums.phpfreaks.com/topic/39503-solved-please-help-with-this/#findComment-190930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.