Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] Recorrer array tipo object

Estas en el tema de Recorrer array tipo object en el foro de PHP en Foros del Web. Hola a todos, este es el primer tema que abro en el foro, hace much韘imo que no tocaba nada de PHP y me ha surgido ...
  #1 (permalink)  
Antiguo 05/06/2013, 03:05
 
Fecha de Ingreso: junio-2013
Mensajes: 5
Antig黣dad: 13 a駉s, 3 meses
Puntos: 0
Recorrer array tipo object

Hola a todos, este es el primer tema que abro en el foro, hace much韘imo que no tocaba nada de PHP y me ha surgido un problemilla a ver si alguien puede ayudarme, mi problema es el siguiente.

Estoy llamando a un web service de SAP desde PHP,

$result = $client->ZTestUwl($params);

esta parte la hace bien porque si hago un print_r ($result); me muestra todos los datos de la tabla que me traigo del web service.

lo que necesitar韆 es poder recorrer cada una de las entradas que me he tra韉o, en un ejemplo que he visto en el foro un usuario hab韆 usado esto y le funciono

foreach($result->item as $v)
{
echo $v->Subject;
}

pero ... me da el siguiente error:

Notice: Undefined property: stdClass::$item in
C:\xampp\htdocs\test\bandeja.php on line 38

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\test\bandeja.php on line 38

Muchas gracias de antemano!! :)
  #2 (permalink)  
Antiguo 05/06/2013, 03:20
Avatar de bookmaster  
Fecha de Ingreso: febrero-2002
Ubicaci髇: Toledo
Mensajes: 976
Antig黣dad: 24 a駉s, 7 meses
Puntos: 67
Respuesta: Recorrer array tipo object

Como ya te puse en el otro post, muestra la estructura del array para ver que nombres recibes, para ver si es correcto.
__________________
Decir si te a funcionado la respuesta es RATIS!. Por favor indicarlo.
http://www.lohacemosweb.net
http://tutoriales.lohacemosweb.net
  #3 (permalink)  
Antiguo 05/06/2013, 04:13
 
Fecha de Ingreso: junio-2013
Mensajes: 5
Antig黣dad: 13 a駉s, 3 meses
Puntos: 0
Respuesta: Recorrer array tipo object

Hola,

La estructura que uso es la siguiente:

El nombre del tipo tabla es: E_BANDEJA_ENTRADA

y su estructura:

USER_ID SYUNAME CHAR 12
EXTERNAL_ID UWLEXTID CHAR 300
EXTERNAL_TYPE UWLTYPE CHAR 255
SUBJECT UWLTYPE CHAR 255
CREATED_TIME TIMESTAMPL DEC 21
ITEM_TYPE UWLTYPE CHAR 255
STATUS UWLSTRING_S CHAR 12
APP_ID HAP_APPRAISAL_ID CHAR 32
  #4 (permalink)  
Antiguo 05/06/2013, 04:14
Avatar de bookmaster  
Fecha de Ingreso: febrero-2002
Ubicaci髇: Toledo
Mensajes: 976
Antig黣dad: 24 a駉s, 7 meses
Puntos: 67
Respuesta: Recorrer array tipo object

Me refer韆 a lo que te devuelve al array cuando le haces el print_r.
__________________
Decir si te a funcionado la respuesta es RATIS!. Por favor indicarlo.
http://www.lohacemosweb.net
http://tutoriales.lohacemosweb.net
  #5 (permalink)  
Antiguo 05/06/2013, 04:23
 
Fecha de Ingreso: junio-2013
Mensajes: 5
Antig黣dad: 13 a駉s, 3 meses
Puntos: 0
Respuesta: Recorrer array tipo object

stdClass Object ( [EBandejaEntrada] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039029 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130603113111.121468 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 519C62955DE10B60E10080000A17383D ) [1] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039027 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130522152523.009888 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 519C629F5DE10B60E10080000A17383D ) [2] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039016 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130514120737.822142 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5191890C56A20B60E10080000A17383D ) [3] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039012 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130513143539.007988 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 518FCE36CB400B60E10080000A17383D ) [4] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039008 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130513140628.642129 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 518E669552D210C0E10080000A17383D ) [5] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000039004 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130513112310.884388 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 518F81E2CB400B60E10080000A17383D ) [6] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038372 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130424160511.081657 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5176FCD65E940A30E10080000A17383D ) [7] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038368 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130424155447.277941 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5176F78B5E940A30E10080000A17383D ) [8] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038361 [ExternalType] => TS99900071 [Subject] => Seguimiento evaluaci贸n SGD COMOS COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130409133322.888841 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5140112B6B1A0970E10080000A17383D ) [9] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038353 [ExternalType] => TS99900071 [Subject] => Seguimiento evaluaci贸n SGD COMOS COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130409092625.558955 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5163581B3BF00A30E10080000A17383D ) [10] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038342 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s SALMERON LOPEZ, MARIA - A帽o 2013 [CreatedTime] => 20130405081407.99325 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 515E27FE3E5D0A30E10080000A17383D ) [11] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038338 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130404115344.083253 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 515D1777256E09C0E10080000A17383D ) [12] => stdClass Object ( [UserId] => 5322 [ExternalId] => 000000038330 [ExternalType] => TS99900070 [Subject] => Evaluaci贸n de SGD COMOS s COMOS COMPTENCIAS, 1007 - A帽o 2013 [CreatedTime] => 20130402152741.040776 [ItemType] => uwl.task.webflow [Status] => NEW [AppId] => 5156B2A6E7AB09C0E10080000A17383D ) ) ) )
  #6 (permalink)  
Antiguo 05/06/2013, 04:33
Avatar de bookmaster  
Fecha de Ingreso: febrero-2002
Ubicaci髇: Toledo
Mensajes: 976
Antig黣dad: 24 a駉s, 7 meses
Puntos: 67
Respuesta: Recorrer array tipo object

En principio ser韆 algo as�:
foreach($result->EBandejaEntrada as $v){
echo $v->item->Subject;
}
__________________
Decir si te a funcionado la respuesta es RATIS!. Por favor indicarlo.
http://www.lohacemosweb.net
http://tutoriales.lohacemosweb.net
  #7 (permalink)  
Antiguo 05/06/2013, 04:43
 
Fecha de Ingreso: junio-2013
Mensajes: 5
Antig黣dad: 13 a駉s, 3 meses
Puntos: 0
Respuesta: Recorrer array tipo object

Hola, muchas gracias por tu ayuda. ahora me esta dando el siguiente error:

Notice: Trying to get property of non-object in C:\xampp\htdocs\test\bandeja.php on line 40

Notice: Trying to get property of non-object in C:\xampp\htdocs\test\bandeja.php on line 40

gracias
  #8 (permalink)  
Antiguo 05/06/2013, 04:50
Avatar de bookmaster  
Fecha de Ingreso: febrero-2002
Ubicaci髇: Toledo
Mensajes: 976
Antig黣dad: 24 a駉s, 7 meses
Puntos: 67
Respuesta: Recorrer array tipo object

Tienes que ajustar el n鷐ero de niveles que tengas, cada nivel que tengas hay que agregarle un ->.

Es que sin tener yo los datos no puedo recrear el ejemplo, y lo estoy haciendo de cabeza, y por aproximaci髇 a lo que quieres.
__________________
Decir si te a funcionado la respuesta es RATIS!. Por favor indicarlo.
http://www.lohacemosweb.net
http://tutoriales.lohacemosweb.net
  #9 (permalink)  
Antiguo 05/06/2013, 05:51
 
Fecha de Ingreso: junio-2013
Mensajes: 5
Antig黣dad: 13 a駉s, 3 meses
Puntos: 0
Respuesta: Recorrer array tipo object

Gracias, por la ayuda. Ya he encontrado la Solucion.

el C骴igo que he usado es el siguiente:

// Llamada al web service
$result = $client->ZTestUwl($params);

// la tabla que retorna
$v = $result->EBandejaEntrada->item;

// recorro tantas veces como entradas
for($i=0;$i<count($v);$i++){
echo $v[$i]->UserId;
echo$v[$i]->Subject;
}

Mil Gracias!

Etiquetas: object, tabla, tipo
Atenci髇: Est醩 leyendo un tema que no tiene actividad desde hace m醩 de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:25.