0

I'm sorry for this question, I'm sure is a noob question.

But... I'm not able to manage that and I'm sorry for asking your help.

I have this script:

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

I'm obtaining this kind of array:

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

How could I obtain an array which directly give me: [0] => AldwychVertigos.png, [1] => celticnewcastle.png, etc?

Thank you

1
  • Does this make an infinite loop? I'd think fetch_all in a while would keep going Commented Mar 18, 2019 at 21:58

2 Answers 2

1

To build a single dimension array you need to either use fetch_row instead of fetch_all and push the single column into the array, instead of the entire result set, ie:

<?php
    $query  = "SELECT logo FROM club";
    $result = $con->query($query);
    $array  = [];
    while($row = $result->fetch_row()){
      $array[] = $row[0];
    }
    print_r($array);
?>
Sign up to request clarification or add additional context in comments.

Comments

0

You want to use fetch() in while loops, not fetchAll(). fetchAll pulls all the rows at once.

1 Comment

While you are technically correct, you're assuming he is using PDO, the use of the constant MYSQLI_NUM and fetch_all shows he is using the MySQLi extension directly and as such the correct method to call is fetch_row.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.