0

i have a table with 2 calumes,"id" and "mobile", i want get all mobile number of database and insert into a array like this $parameters['to'] = array("mobile_number1","mobile_number2","mobile_number3" ,...,"mobile_number last in database"); how to change this code for my request:

  DB_Connect(); // connect function
  $result = DB_Select("SELECT * FROM bs_Content");
  $num_rows = mysqli_num_rows($result);
  while($row = mysqli_fetch_assoc($result)){
     $i = $row['id'];
     $id[$i] = $row['mobile'];
  }
  for($i=1 ; $i<=$num_rows ; $i++){
     print_r($id[$i]);  
  }
  DB_Disconnect();

 // total i wand like array("9380009010","9380002020","930002021");
mjmi
  • 1
  • 1
  • 1

1 Answers1

0

try this..

$numbers[];
  while($row = mysqli_fetch_assoc($result)){
     $numbers[] = $row['mobile'];
  }
Syed Arif Iqbal
  • 1,830
  • 12
  • 16
  • tanks for answer.i wand send sms with a api and i need to get mobile number of database and inset in array then put in variable like $parameters['to'] = array("9380009010","9380002020","930002021",...); and send how i can do? – mjmi Oct 28 '14 at 10:34
  • vote me if this answer is useful for you. any way. try this for setting into `$parameters['to'] = $numbers;` – Syed Arif Iqbal Oct 28 '14 at 11:00
  • DB_Connect(); $result = DB_Select("SELECT * FROM bs_Content"); $num_rows = mysqli_num_rows($result); $numbers[]; while($row = mysqli_fetch_assoc($result)){ $numbers[] = $row['mobile']; } $parameters['to'] = $numbers; --------> Cannot use [] for reading in C:\wamp\www\myschools.ir\index.php on line 9 – mjmi Oct 28 '14 at 11:23
  • `DB_Connect();` `$parameters = [];` `$result = DB_Select("SELECT * FROM bs_Content"); ` `$num_rows = mysqli_num_rows($result); ` `$numbers[]; ` `while($row = mysqli_fetch_assoc($result)){ ` ` $numbers[] = $row['mobile']; ` `}` `$parameters['to'] = $numbers;` – Syed Arif Iqbal Oct 28 '14 at 11:46
  • this code dont work show error pleas you check this code – mjmi Oct 28 '14 at 12:18
  • show me like http://stackoverflow.com/questions/3820258/cannot-use-for-reading error – mjmi Oct 28 '14 at 12:21