Retroceder   Foros del Web > Programación para sitios web > PHP > PHP orientado a objetos

Respuesta
 
Herramientas Desplegado
Antiguo 18-abr-2008, 09:31   #1 (permalink)
SidP no se puede cailificar en este momento
 
Avatar de SidP
 
Fecha de Ingreso: febrero-2006
Ubicación: /etc/php.ini
Mensajes: 121
obtener elemento de un array

hola comunidad
no tengo claro como podria hacerlo..
tengo estas funciones
Código:
public function bindList(){
   $stu_num=$_GET['id'];
   return $this->_studentDetails=    StudentPeer::doSelectStudentDetails($stu_num));
  }
la otra funcion en la clase StudentPeer
Código:
public function doSelectStudentDetails($stu_num){
  return StudentRecord::finder()->findAllBystu_num($stu_num); //retorna un array de objetos
}
es decir en mi caso me retorna esto este array
Código:
StudentRecord Object ( [stu_num] => 470029898 [stu_fname] => test [stu_lname] => test [stu_email] => tes@example.com [stu_username] => tes [stu_birthdate] => 2007-04-18 00:00:00 [stu_phone] => [stu_sex] => F [stu_province_code] => 21 [group_num] => 108 [stu_municipality] => xxxx[stu_password] => e10adc3949ba59abbe56e057f20f88 [stu_active] => 1 [stu_number] => 18 [_readOnly:private] => [_connection:private] => TDbConnection Object ( [_dsn:private] => mysql:host=localhost;dbname=proyecto [_username:private] => root [_password:private] => nightwish [_attributes:private] => Array ( ) [_active:private] => 1 [_pdo:private] => PDO Object ( ) [_e:private] => Array ( ) ) [_e:private] => Array ( ) )
como podria sacar los datos por ejemplo del campo stu_lname

gracias de antemano

Última edición por SidP; 18-abr-2008 a las 10:17. Razón: salida del arreglo
SidP está desconectado   Responder Citando
Antiguo 18-abr-2008, 12:58   #2 (permalink)
Moderador
GatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy prontoGatorV llegará a ser famoso muy pronto
 
Avatar de GatorV
 
Fecha de Ingreso: mayo-2006
Ubicación: Queretaro, Mexico
Mensajes: 11.280
Re: obtener elemento de un array

Hola SidP,

En el código que expones, lo que te regresa es un objeto, no un arreglo, podrías accesar así:
Código PHP:
echo $result->stu_lname
Saludos.
__________________
Blog Web
GatorV está desconectado   Responder Citando
Antiguo 18-abr-2008, 13:33   #3 (permalink)
SidP no se puede cailificar en este momento
 
Avatar de SidP
 
Fecha de Ingreso: febrero-2006
Ubicación: /etc/php.ini
Mensajes: 121
Re: obtener elemento de un array

hola GatorV y gracias por responder.....
mira lo que tengo
Código:
object(StudentRecord)#119 (17) { ["stu_num"]=>  string(9) "470029898" ["stu_fname"]=>  string(4) "test" ["stu_lname"]=>  string(4) "test" ["stu_email"]=>  string(22) "test@example.com" ["stu_username"]=>  string(3) "tes" ["stu_birthdate"]=>  string(19) "2007-04-18 00:00:00" ["stu_phone"]=>  NULL ["stu_sex"]=>  string(1) "F" ["stu_province_code"]=>  string(2) "21" ["group_num"]=>  string(3) "108" ["stu_municipality"]=>  string(7) "Jiguani" ["stu_password"]=>  string(30) "e10adc3949ba59abbe56e057f20f88" ["stu_active"]=>  string(1) "1" ["stu_number"]=>  string(2) "18" ["_readOnly:private"]=>  bool(false) ["_connection:private"]=>  object(TDbConnection)#27 (7) { ["_dsn:private"]=>  string(36) "mysql:host=localhost;dbname=proyecto" ["_username:private"]=>  string(4) "root" ["_password:private"]=>  string(9) "xxxxx" ["_attributes:private"]=>  array(0) { } ["_active:private"]=>  bool(true) ["_pdo:private"]=>  object(PDO)#79 (0) { } ["_e:private"]=>  array(0) { } } ["_e:private"]=>  array(0) { } }
si lo hago de esa forma lo que obtengo es esto
Código:
[Notice] Trying to get property of non-object
ahora si lo hago de esta forma
Código:
 
print_r($this->_studentDetails[0]->stu_lname) ahora si me va bien
...solo tenia que agregarle el subindice.

Muchisimas Gracias
SidP está desconectado   Responder Citando
Respuesta
No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 21:52.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93