【问题标题】:how to add mobile number fetching of database insert into array如何将数据库插入的手机号码提取添加到数组中
【发布时间】:2014-12-23 15:43:03
【问题描述】:

我有一个包含 2 个 calumes、“id”和“mobile”的表,我想获取数据库的所有手机号码并插入到这样的数组中 $parameters['to'] = array("mobile_number1","mobile_number2 ","mobile_number3" ,...,"mobile_number 最后在数据库中"); 如何根据我的请求更改此代码:

  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");

【问题讨论】:

    标签: arrays


    【解决方案1】:

    试试这个..

    $numbers[];
      while($row = mysqli_fetch_assoc($result)){
         $numbers[] = $row['mobile'];
      }
    

    【讨论】:

    • 答案的坦克。我用 api 发送短信,我需要获取数据库的手机号码并在数组中插入,然后放入变量,如 $parameters['to'] = array("9380009010" ,"9380002020","930002021",...);并发送我该怎么办?
    • 如果此答案对您有用,请投票给我。反正。试试这个设置成$parameters['to'] = $numbers;
    • DB_Connect(); $result = DB_Select("SELECT * FROM bs_Content"); $num_rows = mysqli_num_rows($result); $数字[]; while($row = mysqli_fetch_assoc($result)){ $numbers[] = $row['mobile']; } $parameters['to'] = $numbers; --------> 不能使用 [] 在第 9 行的 C:\wamp\www\myschools.ir\index.php 中读取
    • 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;
    • 此代码不起作用显示错误请检查此代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多