I have a column in my database that essentially creates an array and I am essentially trying to explode it but I cannot figure out how to get it to work. Its also going into SQL with { characters that are not helping the situation.
When I run the query:
$query = "SELECT awaylineup FROM #__baseball_lineup";
$db->setQuery($query);
$lineups = $db->loadObjectList();
foreach($lineups as $lineup){
$players = explode(" ", $lineup->awaylineup);
}
The results come out as:
{"awaylineup0":"order":"0","player":"1","position":"2"},"awaylineup1":"order":"1","player":"3","position":"3"},"awaylineup2":{"order":"2","player":"2","position":"9"}}
I am trying to get:
[awaylineup0] => Array
(
[order] => 1
[player] => 1
[position] =>2
)
[awaylineup1] => Array
(
[order] => 1
[player] => 3
[position] =>3
)
[awaylineup2] => Array
(
[order] => 2
[player] => 2
[position] =>9
)
I don't know how many foreach's I have to run to get that, but also how to remove the {} characters in the string?
Update
> array ( 0 => NULL, 1 =>
> '{"awaylineup0":{"order":"0","player":"1","position":"2"},"awaylineup1":{"order":"1","player":"3","position":"3"},"awaylineup2":{"order":"2","player":"2","position":"9"}}',
> 2 =>
> '{"awaylineup0":{"order":"0","player":"1","position":"1"},"awaylineup1":{"order":"1","player":"2","position":"9"},"awaylineup2":{"order":"2","player":"3","position":"6"}}',
> )