Reputation: 115
I use a library for Synchronize a local WebSQL DB to a server specifically https://github.com/orbitaloop/WebSqlSync. I use PHP: 5.4.7, When I try to get the array values as follows, I get the message
Illegal string offset 'clientes'
the $obj var is:
Array
(
[info] =>
[data] => Array
(
[clientes] => Array
(
)
[conceptos_gastos] => Array
(
)
[formaspago] => Array
(
[0] => Array
(
[idFormaPago] => 10
[FormaPago] => qwerqwe
[Dias] => 1
[Cuotas] => 1
[last_sync_date] =>
)
)
[listaprecios] => Array
(
)
[producto] => Array
(
)
[repartidores] => Array
(
)
[tipodocumento] => Array
(
)
[vehiculos] => Array
(
)
[zonas] => Array
(
)
)
)
this is the loop
foreach ($obj as $row => $value) {
echo $row["clientes"]["fomaspago"]["FormaPago"];
}
eternally grateful for any help
Upvotes: 0
Views: 5053
Reputation: 115
thanks to all but the only way that worked was as follows:
foreach($obj->data->formaspago as $formaspago) {
print " id ".$formaspago->idFormaPago;
print " Formapago ".$formaspago->FormaPago;
print " dias ".$formaspago->Dias;
print " cuotas ".$formaspago->Cuotas;
print " lastsyncdate ".$formaspago->last_sync_date;
}
foreach($obj->data->clientes as $formaspago) {
print " id ".$formaspago->IdCliente;
print " Cliente ".$formaspago->Cliente;
}
Upvotes: 0
Reputation: 4875
it seems to be
$row["data"]["clientes"] // which is an empty array
or
$row["data"]["formaspago"][0]["FormaPago"] // which should output "qwerqwe"
Upvotes: 2
Reputation: 7530
The element $row["clientes"]["fomaspago"]["FormaPago"]; does indeed not exist - look at the output: the 1st row "info" does not have that index, the 2nd row "data" has "clientes" and also "fomasgapo", but does not have a "clientes" "fomasgapo". You need to either structure your data differently or loop through it differently...
Upvotes: 0