【问题标题】:Not able to get list of arrays in php无法在php中获取数组列表
【发布时间】:2023-02-26 12:17:34
【问题描述】:

我正在从我的远程数据库接收数据,我被困在如何在一个列表中打印所有数组,谁能帮助我,谢谢

  • 这是我的 php 代码

 <?php

   include('db.php');

   $conn = mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
   if (!$conn) {
     die("Connection failed: " . mysqli_connect_error());
   } else {
      getCountryInfo();
   }


  function getCountryInfo(){

    global $conn;
    $values_array = array();
   
    $sql = "SELECT * FROM `countryInfo`ORDER BY `countryID`";
    $result = mysqli_query($conn,$sql);

    while ($row = mysqli_fetch_assoc($result)) {
     
      $values_array[]   = $row['countryName'];
      $values_array[]   = $row['countryPhone'];
      $values_array[]   = $row['countryCurrency'];
       
      // i'm getting each 3 values in one array , now i want to add each array to a list  
      // so that i finally get list of arrays 

    }

   
     mysqli_close($conn);
      
  }

?>

【问题讨论】:

  • 看起来像是一个可能的查询错字? ... ORDER BY 前需要一个空格。将 `countryInfo`ORDER BY 更改为 `countryInfo` ORDER BY
  • @保罗。我得到了所有值,值没有问题,因为我需要将数据导入我的 android 应用程序,我想从 php 中回显数据作为数据列表(或数组列表),因为每一行都有 3 个值,想要每个数组中的 3 个值,然后将这些数组添加到列表中并为我的 android 应用回显它,希望你明白我的意思,谢谢

标签: php


【解决方案1】:
$values_array[] = [
    'countryName'=> $row['countryName'],
    'countryPhone'=> $row['countryPhone'],
    'countryCurrency'=> $row['countryCurrency']
];

【讨论】:

  • 非常感谢,正是我所需要的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-29
  • 2017-04-30
相关资源
最近更新 更多