Good evening. I don’t understand how to implement a little ... See, connect to the database and sample

<?php $db = new SQLite3('****'); $results = $db->query('SELECT player FROM **** '); while ($row = $results->fetchArray()) { print_r($row); } ?> 

But the result is ([0] => Madii [player] => Madii) ... I need to get only Madii at the output. Please tell me what I did wrong ... On the php site I’m not working ... But the problem is that everything is in English (I don’t understand everything), and generally novice in programming. Thank you very much.

  • if php in the address bar replace en with ru, then a little magic happens - etki
  • print_r ($ row [0] ['Madii [player]']); Or if you need to disassemble $ row array, in parts, then look away: foreach ($ array as $ key => $ value) {} - lightcyber

1 answer 1

Judging by the docks , you need to do this:

 <?php $db = new SQLite3('****'); $results = $db->query('SELECT player FROM **** ', SQLITE3_ASSOC); $playerNames = array(); // инициализируем массив для имен игроков while ($row = $results->fetchArray()) { $playerNames[] = $row['player']; // добавляем в массив новый элемент, доставая его из массива $row } print_r($playerNames); ?> 

By default, the second parameter is SQLITE3_BOTH, which returns all fields using both numeric and numbered keys.

update: I'm stupid, just now I understood what output is required, updated the answer.

  • Yes Yes Yes Yes. I just found it myself. Here I came to write to you. I watched the code on the website if-not-true-then-false.com/2012/php-pdo-sqlite3-example and saw an implementation example there, just added print_r ($ row ['player']) ;. Thank you very much. I apologize for my stupid questions. All the best to you, I hope someday I will be as good at understanding all this as you. - istimbi
  • @istimbi, this entire site exists to ask questions that are answered correctly. I sometimes appear here with questions of the same initial level on C, for example - etki