Я пытаюсь сделать цикл в php, который будет проходить через массив MySQL и извлекать некоторую информацию в зависимости от переменной.
Таблица в MySQL выглядит следующим образом: id, slot1, slot2, slot3, ... slot12.
$max_player_slots = 5;
//***Create Inventory Array**//
$inventory_info = "SELECT * from inventory where id = $player_id";
$inventory_info2 = mysql_query($inventory_info) or die ("Couldn't get inventorys stats");
$inventory_info3 = mysql_fetch_array($inventory_info2);
//depending on max player slots insert that many values into &invSlots array
for( $i = 1, $invSlots = array(); $i > $max_player_slots; $i++){
$invSlots[$i] = $inventory_info3[$i]; //here is the problem i dont know how to insert the diferent values using $i
}
$json = $invSlots;
$encoded = json_encode($json);
die ($encoded);
Я ожидаю, что массив $ invSlots после этого будет содержать:
$invSlots = array(slot1, slot2, slot3, slot4, slot5);
но я просто получаю ошибку.
Я думаю, причина в том, что информация о массиве mysql хранится в ассоциативном массиве, и я пытаюсь получить к нему цифровой доступ? но я не знаю, как ее решить.