0

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

2
  • Seems like data should be your first dimension in your array. Commented Jul 15, 2013 at 16:47
  • use $obj["data"] instead of $obj in foreach loop Commented Jul 15, 2013 at 16:48

3 Answers 3

2

it seems to be

$row["data"]["clientes"] // which is an empty array 

or

$row["data"]["formaspago"][0]["FormaPago"] // which should output "qwerqwe"
Sign up to request clarification or add additional context in comments.

1 Comment

I tried the following: foreach ($obj as $row => $value) { $row["clientes"]["fomaspago"][0]["FormaPago"]; } and still the same error message also $row["data"]["formaspago"][0]["FormaPago"]
0

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...

2 Comments

i tried $row["data"]["formaspago"][0]["FormaPago"] and still the same error , also $row["data"]["formaspago"]["FormaPago"]
Yes, because these elements are not there! BTW, you can avoid the error by checking if (isset($row...index...)) beforehand...
0

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; 

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.