while数组错误

时间:2019-03-18 21:53:37

标签: php arrays while-loop

很抱歉这个问题,我确定是一个菜鸟问题。

但是...我无法解决这个问题,很抱歉要求您的帮助。

我有这个脚本:

   <?php
       $query = "SELECT logo FROM club";
       $result = $con->query($query);
       while($row = $result->fetch_all(MYSQLI_NUM)){
       print_r($row);
   }
   ?>

我正在获得这种数组:

Array ( [0] => Array ( [0] => AldwychVertigos.png ) [1] => Array ( [0] => celticnewcastle.png ) [2] => Array ( [0] => Darkwear.png ) [3] => Array ( [0] => InterUltrafox.png ) [4] => Array ( [0] => IrefulXI.png ) [5] => Array ( [0] => KensingtonWest.png ) [6] => Array ( [0] => Vandyke.png ) [7] => Array ( [0] => ZetaUnited.png ) [8] => Array ( [0] => ZigZag.png ) [9] => Array ( [0] => ZionPark.png ) [10] => Array ( [0] => Ignitabulum.png ) [11] => Array ( [0] => AgileVigne.png ) [12] => Array ( [0] => BravaZena.png ) [13] => Array ( [0] => ItalianWarriors.png ) [14] => Array ( [0] => MWM.png ) [15] => Array ( [0] => NavyBlu.png ) [16] => Array ( [0] => SCEsseErre.png ) [17] => Array ( [0] => VoxPopuli.png ) [18] => Array ( [0] => Zanzare.png ) [19] => Array ( [0] => ZebreRoma.png ) [20] => Array ( [0] => AmbrosianaFC.png ) [21] => Array ( [0] => ClubPhoenix.png ) [22] => Array ( [0] => DinamoKangaroo.png ) [23] => Array ( [0] => FioreFC.png ) [24] => Array ( [0] => Kogins.png ) [25] => Array ( [0] => LupoTosco.png ) [26] => Array ( [0] => Sporting.png ) [27] => Array ( [0] => Torino49.png ) [28] => Array ( [0] => Xugia2004.png ) [29] => Array ( [0] => Young00.png ) ) 

如何获得直接给我的数组: [0] => AldwychVertigos.png, [1] => celticnewcastle.png,等等?

谢谢

2 个答案:

答案 0 :(得分:1)

要构建一个单维数组,您需要使用fetch_row而不是fetch_all并将单列而不是整个结果集推入数组,即:

<?php
    $query  = "SELECT logo FROM club";
    $result = $con->query($query);
    $array  = [];
    while($row = $result->fetch_row()){
      $array[] = $row[0];
    }
    print_r($array);
?>

答案 1 :(得分:0)

您要在while循环中使用fetch(),而不要在fetchAll()中使用。 fetchAll一次提取所有行。