So I was as normal fetching results from my MYSQL database using PDO from a view table I created, all is fine with var_dump and print_r UNTIL I try to set the result to any array key.
public function getBag($user = false)
{
$id = ($user) ? $user['id'] : $_SESSION['user']['id'];
$bag = $this->prepareFromArray('bag', array('user_id' => $id), 'select', 'all', array('user_id'));
$result = (isset($bag[0]['id'])) ? $bag : null;
return $result;
}
public function prepPlayer($user)
{
$user['medals'] = $this->getmedals($user);
$user['pokemons'] = $this->getPokemons($user);
$user['bag'] = $this->getBag($user);
for ($i=0; $i < 6; $i++) {
$user['pokemons']['roster'][$i] = (isset($user['pokemons']['roster'][$i])) ? $user['pokemons']['roster'][$i] : ['name' => "None", "level" => 0, "wild_id" => 0, "color" => 0];
}
$trainerClass = strtolower(trim($user['class']));
$cover = "img/Trainers/$trainerClass/background/{$user['wallpaper']}.png";
$user['cover'] = (file_exists($_SERVER['DOCUMENT_ROOT']."/$cover")) ? $cover : "img/Trainers/backgrounds/1.png";
return $user;
}
I am using the prepPlayer method to prepare players when called upon, everything works fine UNTIL we get to getting the players bag.
if I comment out the db (prepareFromArray) method it will naturaly work, if I print_r the bag variable, it shows all items from the bag view, but once I try to return the result into the $user['bag'] array element all hell breaks lose, and the result is a blank page for my stream file that depends on this. I am using
echo json_encode(array('result' => $user), JSON_NUMERIC_CHECK);
to output the result to my angular service.
here is how my bag view looks like
CREATE VIEW `bag` AS
SELECT
`player_items`.`id` AS `id`,
`players`.`id` AS `user_id`,
`items`.`id` AS `item`,
`items`.`qual` AS `qual`,
`items`.`cat` AS `cat`,
`items`.`name` AS `name`,
`items`.`description` AS `description`,
`items`.`chance` AS `chance`,
`items`.`cost` AS `cost`,
`items`.`trade` AS `trade`,
`player_items`.`amount` AS `amount`,
`player_items`.`cap` AS `cap`,
`player_items`.`sell` AS `sell`,
`items`.`temp` AS `temp`
FROM
((`players`
JOIN `items`)
JOIN `player_items`)
WHERE
((`players`.`id` = `player_items`.`user_id`)
AND (`player_items`.`item_id` = `items`.`id`))
ORDER BY `player_items`.`id`