-1

I have write some code for send sms to multiple users with database values i will get the mobile numbers to that code but i will send sms to that only single mobile number msg can passed remain numbers not accepting but i have send the no of mobile numbers are there all members msg will send i will write some code in here once check how to send and also i will try this code working only one mobile number

in the below code i will get records 2.

mobile numbers are also display 2 values.

sendSMS() function i will placed in while loop and outer while loop but last record will be selected.

$get_donor = "SELECT * FROM donor_register WHERE `dnr_bloodgroup` ='$blood_group' and `dnr_city` = '$city' ";
          $get_result = $conn->query($get_donor);
            $count = $get_result->num_rows;

            if($count > 0)
            {
            while($row = $get_result->fetch_assoc())
            {
                  $phone ='';
                  $phone .=$row['dnr_phone']; 
                  echo $phone;
           } 
           sendSMS("Pname",$phone,$message);
         }

My sendSMS function like this

function sendSMS($sender, $mobile_number, $message)
{
//some code 
}

I Expected out put is Pname 3214569870,7412589630,4561237890... this will i will ecpected

But i have get it pname 3214569870 only.

Dharman
  • 26,923
  • 21
  • 73
  • 125

4 Answers4

1

declare $phone variable out side of while loop

$phone ='';
while($row = $get_result->fetch_assoc())
            {
                  if($phone) {
                       $phone .=','.$row['dnr_phone']; 
                  } else {
                       $phone .=$row['dnr_phone']; 
                  }

                  echo $phone;
           }
Devsi Odedra
  • 5,071
  • 1
  • 21
  • 33
1
    if($count > 0)
    {   
        $phone ='';
        while($row = $get_result->fetch_assoc())
        {
            if($phone==''){
                $phone .=$row['dnr_phone']; 
            }else{
                $phone .=','.$row['dnr_phone']; 
            }
            echo $phone;
        } 
        sendSMS("Pname",$phone,$message);
    }
1

Try this

    $phone ='';
    while($row = $get_result->fetch_assoc())
    {

      if($phone && $row['dnr_phone']) {
          $phone .= ',';
        } 
      $phone .=$row['dnr_phone'];
    }
    echo $phone;
-1

Due to above code, $phone takes only last mobile number,because sendSMS function called after while loop.

Solution:: sendSMS("Pname",$phone,$message); This function should be in while loop.