Foros del Web » Programando para Internet » PHP »

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\

Estas en el tema de Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\ en el foro de PHP en Foros del Web. la ejecucion de los siguientes dos archivos me tira esta adverencia la tabla que maneja es users ayuda please!!! gracias de antemano!! este es el ...
  #1 (permalink)  
Antiguo 21/11/2011, 13:22
 
Fecha de Ingreso: mayo-2010
Mensajes: 12
Antigüedad: 14 años
Puntos: 0
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\

la ejecucion de los siguientes dos archivos me tira esta adverencia
la tabla que maneja es users

ayuda please!!!

gracias de antemano!!


este es el código
---------------------------

usuario.php
........................
<html>
<head>
<title></title>
</head>
<body>
<?php
include_once ("clase.php"); // incluye las clases
$calle="";
$numero="";
$distrito="";
$departamento="";
$nombre="";
$apellido="";
$profesion="";
$telefono="";
$email="";
$dni="";
$users="";
$id="";

if (isset($_GET['md'])) // si la operacion es modificar, este valor viene seteado y ejecuta el siguiente codigo
{
$usuario=new Usuario($_GET['md']); // instancio la clase cliente pasandole el nro de cliente, de esta forma lo busca
$nombre=$usuario->getNombre(); // obtengo el nombre
$apellido=$usuario->getApellido(); // obtengo el apellido
$profesion =$usuario->getProfesion;
$telefono=$usuario->getTelefono;
$email=$usuario->getEmail;
$dni=$usuario->getDni;
$calle=$usuario->getCalle();
$numero=$usuario->getNumero();
$distrito=$usuario->getDistrito();
$departamento=$usuario->getDepartamento();
$id=$usuario->getId(); // obtengo el id

}
?>

<div >
<form method="POST" action="usuarios.php">
<input type="hidden" name="id" value="<?php print $id ?>">
<table border=1>

<tr>
<td>Nombre</td>
<td><input type="text" name="nombre" value = "<?php print $nombre ?>"></td>
</tr>
<tr>
<td>Apellido</td>
<td><input type="text" name="apellido"value = "<?php print $apellido ?>"></td>
</tr>
<tr>
<td>Profesion</td>
<td><input type="text" name="profesion"value = "<?php print $profesion ?>"></td>
</tr>

<tr>
<td>Telefono</td>
<td><input type="text" name="telefono"value = "<?php print $telefono ?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"value = "<?php print $email ?>"></td>
</tr>
<tr>
<td>DNI</td>
<td><input type="text" name="dni"value = "<?php print $dni ?>"></td>
</tr>
<tr>
<td>Calle</td>
<td><input type="text" name="calle"value = "<?php print $calle ?>"></td>
</tr>
<tr>
<td>Numero</td>
<td><input type="text" name="numero"value = "<?php print $numero ?>"></td>
</tr>
<tr>
<td>Distrito</td>
<td><input type="text" name="distrito"value = "<?php print $distrito ?>"></td>
</tr>
<tr>
<td>Departamento</td>
<td><input type="text" name="departamento"value = "<?php print $departamento ?>"></td>
</tr>
<tr>
<td></td>
<td align =right><input type="submit" name="submit" value ="<?php if(is_numeric($id)) print "Modificar"; else print "Ingresar";?>"></td>
</tr>
</table>
</form>
</div>
<?php




if (isset($_POST['submit'])&&!is_numeric($_POST['id'])) // si presiono el boton ingresar
{
$usuario=new Usuario();
//print_r($_POST);
$usuario->setNombre($_POST['nombre']); // setea los datos
$usuario->setApellido($_POST['apellido']);
$usuario->setProfesion($_POST['profesion']);
$usuario->setTelefono($_POST['telefono']);
$usuario->setEmail($_POST['email']);
$usuario->setDni($_POST['dni']);
$usuario->setCalle($_POST['calle']);
$usuario->setNumero($_POST['numero']);
$usuario->setDistrito($_POST['distrito']);
$usuario->setDepartamento($_POST['departamento']);
print " Consulta ejecutada: ". $usuario->insertUsuario(); // inserta y muestra el resultado
}
if (isset($_POST['submit'])&&is_numeric($_POST['id'])) // si presiono el boton y es modificar
{
$usuario=new Usuario($_POST['id']); // instancio la clase pasandole el nro de cliente para cargar los datos
$usuario->setNombre($_POST['nombre']); // setea los datos nuevos
$usuario->setApellido($_POST['apellido']);
$usuario->setProfesion($_POST['profesion']);
$usuario->setTelefono($_POST['telefono']);
$usuario->setEmail($_POST['email']);
$usuario->setDni($_POST['dni']);
$usuario->setCalle($_POST['calle']);
$usuario->setNumero($_POST['numero']);
$usuario->setDistrito($_POST['distrito']);
$usuario->setDepartamento($_POST['departamento']);
print " Consulta ejecutada: ". $usuario->updateUsuario(); // inserta y muestra el resultado
}
if (isset($_GET['br'])&&is_numeric($_GET['br'])) // si presiono el boton y es eliminar
{
$usuario=new Usuario();
print " Consulta ejecutada: ". $usuario->deleteUsuario($_GET['br']); // elimina el cliente y muestra el resultado
}



$usuario=new Usuario();
$usuarios= $usuario->getUsuarios(); // obtiene todos los clientes para despues mostrarlos

print '<br/><br/><table border=1>'
.'<tr><td>Nombre:</td>'
.'<td>Apellido:</td>'
.'<td>Profesion</td>'
.'<td>Telefono</td>'
.'<td>Email</td>'
.'<td>DNI</td>'
.'<td>Calle</td>'
.'<td>Numero</td>'
.'<td>Distrito</td>'
.'<td>Departamento</td>'
.'<td>Modificar</td>'
.'<td>Borrar</td></tr>';

while ($row=mysql_fetch_Array($users)) // recorre los clientes uno por uno hasta el fin de la tabla
{
print '<tr>'
.'<td>'.$row['nombre'] .'</td>'
.'<td>'.$row['apellido'] .'</td>'
.'<td>'.$row['telefono'] .'</td>'
.'<td>'.$row['email'] .'</td>'
.'<td>'.$row['dni'] .'</td>'
.'<td>'.$row['calle'] .'</td>'
.'<td>'.$row['numero'] .'</td>'
.'<td>'.$row['distrito'] .'</td>'
.'<td>'.$row['departamento'] .'</td>'
.'<td><a href="usuarios.php?md='.$row['id'].'">Modificar</a></td>' // en este ejemplo para simplificar se envian los parametros por get utilizando un href
.'<td><a href="usuarios.php?br='.$row['id'].'">Borrar</a></td>' // lo correcto seria enviarlos por post con un submit por ejem.
.'</tr>';
}
print '</table>';
?>
</body>
</html>
  #2 (permalink)  
Antiguo 21/11/2011, 13:30
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

Y la parte deonde te conectas a la base de datos?

es necesario poner minimamente un mysql_query

un ejemplo rápido de como hacerlo

Código PHP:
Ver original
  1. $con = mysql_connect("localhost","user","pass");
  2. $bd = mysql_select_db("bd") or die ("Verifique la Base de Datos");
  3. $sql = "SELECT * FROM tabla";
  4. $res = mysql_query($sql, $con);
  5. $reg = mysql_fetch_array($res);

esta ultima la puedes recorrer en un while como tu lo haces
  #3 (permalink)  
Antiguo 21/11/2011, 13:34
Avatar de linuxzero  
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

En tu linea cuando hace el mysql_fetch_array() le estas pasando una variable que primero es un string y no un resultset, y ademas esta vacio, porque en ningun lado le asignas contenido.

En esta linea $users deberia ser el resultado de un mysql_query()

Por ejemplo:
Código PHP:
Ver original
  1. $users = mysql_quert("SELECT * FROM tabla") or die(mysql_error());
  2. while ($row=mysql_fetch_Array($users)) // recorre los clientes uno por uno hasta el fin de la tabla

Saludos!
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com
  #4 (permalink)  
Antiguo 21/11/2011, 13:36
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 11 meses
Puntos: 56
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

Lo vi por encima pero creo debes revisar lo que te llega a $users ya que parece estar vacio.

Aparte nunca he probado si mysql_fetch_Array funciona igual con la mayuscula como la tienes o tiene que ser mysql_fetch_array.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #5 (permalink)  
Antiguo 21/11/2011, 14:01
 
Fecha de Ingreso: mayo-2010
Mensajes: 12
Antigüedad: 14 años
Puntos: 0
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

Esta es la parte donde me conecto a la BD
Código PHP:
Ver original
  1. class Conexion  // se declara una clase para hacer la conexion con la base de datos
  2. {
  3.     var $con;
  4.     function Conexion()
  5.              
  6.     {
  7.         // se definen los datos del servidor de base de datos
  8.         $conection['server']="localhost";  //host
  9.         $conection['user']="root";         //  usuario
  10.         $conection['pass']="";      //password
  11.         $conection['base']="mdmbd";         //base de datos
  12.        
  13.        
  14.         // crea la conexion pasandole el servidor , usuario y clave
  15.         $conect= mysql_pconnect($conection['server'],$conection['user'],$conection['pass']);
  16.  
  17.  
  18.            
  19.         if ($conect) // si la conexion fue exitosa , selecciona la base
  20.         {
  21.             mysql_select_db($conection['base']);           
  22.             $this->con=$conect;
  23.         }
  24.     }
  25.     function getConexion() // devuelve la conexion
  26.     {
  27.         return $this->con;
  28.     }
  29.     function Close()  // cierra la conexion
  30.     {
  31.         mysql_close($this->con);
  32.     }  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. class sQuery   // se declara una clase para poder ejecutar las consultas, esta clase llama a la clase anterior
  40. {
  41.  
  42.     var $pconeccion;
  43.     var $pconsulta;
  44.     var $resultados;
  45.     function sQuery()  // constructor, solo crea una conexion usando la clase "Conexion"
  46.     {
  47.         $this->pconeccion= new Conexion();
  48.     }
  49.     function executeQuery($cons)  // metodo que ejecuta una consulta y la guarda en el atributo $pconsulta
  50.     {
  51.         $this->pconsulta= mysql_query($cons,$this->pconeccion->getConexion());
  52.         return $this->pconsulta;
  53.     }  
  54.     function getResults()   // retorna la consulta en forma de result.
  55.     {return $this->pconsulta;} 
  56.    
  57.     function Close()        // cierra la conexion
  58.     {$this->pconeccion->Close();}  
  59.    
  60.     function Clean() // libera la consulta
  61.     {mysql_free_result($this->pconsulta);}
  62.    
  63.     function getResultados() // debuelve la cantidad de registros encontrados
  64.     {return mysql_affected_rows($this->pconeccion->getConexion()) ;}
  65.    
  66.     function getAffect() // devuelve las cantidad de filas afectadas
  67.     {return mysql_affected_rows($this->pconeccion->getConexion()) ;}
  68. }
  69.  
  70.  
  71.  
  72.  
  73. class Usuario
  74. {
  75.     var $calle;     //se declaran los atributos de la clase, que son los atributos del cliente
  76.     var $numero;
  77.     var $distrito;
  78.     var $departamento;
  79.     var $nombre;
  80.     var $apellido;
  81.     var $profesion;
  82.     var $telefono;
  83.     var $email;
  84.     var $dni;
  85.     var $id;
  86.  
  87.    
  88.  
  89.     function Usuario($nro=0) // declara el constructor, si trae el numero de cliente lo busca , si no, trae todos los clientes
  90.     {
  91.         if ($nro!=0)
  92.         {
  93.             $obj_usuario=new sQuery();
  94.             $result=$obj_usuario->executeQuery("select * from users where id = $nro"); // ejecuta la consulta para traer al cliente
  95.             $row=mysql_fetch_array($result);
  96.             $this->id=$row['id'];
  97.             $this->nombre=$row['nombre'];
  98.             $this->apellido=$row['apellido'];
  99.             $this->profesion=$row['profesion'];
  100.             $this->telefono=$row['telefono'];
  101.             $this->email=$row['email'];
  102.             $this->dni=$row['dni'];
  103.             $this->calle=$row['calle'];
  104.             $this->numero=$row['numero'];
  105.             $this->distrito=$row['distrito'];
  106.             $this->departamento=$row['departamento'];
  107.             }
  108.     }
  109.     function getUsuarios() // este metodo podria no estar en esta clase, se incluye para simplificar el codigo, lo que hace es traer todos los clientes
  110.         {
  111.             $obj_usuario=new sQuery();
  112.             $result=$obj_usuario->executeQuery("select * from users"); // ejecuta la consulta para traer al cliente
  113.             return $result; // retorna todos los clientes
  114.         }
  115.        
  116.         // metodos que devuelven valores
  117.     function getId()
  118.      { return $this->id;}
  119.     function getNombre()
  120.      { return $this->nombre;}
  121.     function getApellido()
  122.      { return $this->apellido;}
  123.     function getProfesion()
  124.      { return $this->profesion;}
  125.     function getTelefono()
  126.      { return $this->telefono;}
  127.     function getEmail()
  128.      { return $this->email;}
  129.     function getDni()
  130.      { return $this->dni;}
  131.     function getCalle()
  132.      { return $this->calle;}
  133.     function getNumero()
  134.      { return $this->numero;}
  135.     function getDistrito()
  136.      { return $this->distrito;}
  137.     function getDepartamento()
  138.      { return $this->departamento;}
  139.  
  140.  
  141.         // metodos que setean los valores
  142.     function setNombre($val)
  143.      { $this->nombre=$val;}
  144.     function setApellido($val)
  145.      {  $this->apellido=$val;}
  146.     function setProfesion($val)
  147.      {  $this->profesion=$val;}
  148.     function setTelefono($val)
  149.      {  $this->telefono=$val;}
  150.     function setEmail($val)
  151.      {  $this->email=$val;}
  152.     function setDni($val)
  153.      {  $this->dni=$val;}
  154.     function setCalle($val)
  155.      {  $this->calle=$val;}
  156.     function setNumero($val)
  157.      {  $this->numero=$val;}
  158.     function setDistrito($val)
  159.      {  $this->distrito=$val;}
  160.     function setDepartamento($val)
  161.      {  $this->departamento=$val;}
  162.  
  163.     function updateUsuario()    // actualiza el cliente cargado en los atributos
  164.     {
  165.             $obj_usuario=new sQuery();
  166.             $query="update users set nombre='$this->nombre', apellido='$this->apellido', profesion='$this->profesion', telefono='$this->telefono', email='$this->email', dni='$this->dni', calle='$this->calle', numero='$this->numero' ,distrito='$this->distrito', departamento='$this->departamento' where id = $this->id";
  167.             $obj_usuario->executeQuery($query); // ejecuta la consulta para traer al cliente
  168.         return $query .'<br/>Registros afectados: '.$obj_usuario->getAffect(); // retorna todos los registros afectados
  169.    
  170.     }
  171.     function insertUsuario()    // inserta el cliente cargado en los atributos
  172.     {
  173.             $obj_usuario=new sQuery();
  174.             $query="insert into users( nombre, apellido, profesion, telefono, email, dni, calle, numero, distrito, departamento)values('$this->nombre', '$this->apellido', '$this->profesion', '$this->telefono', '$this->email','$this->dni','$this->calle','$this->numero','$this->distrito','$this->departamento')";
  175.            
  176.             $obj_usuario->executeQuery($query); // ejecuta la consulta para traer al cliente
  177.             return $query .'<br/>Registros afectados: '.$obj_usuario->getAffect(); // retorna todos los registros afectados
  178.    
  179.     }  
  180.     function deleteUsuario($val)    // elimina el cliente
  181.     {
  182.             $obj_usuario=new sQuery();
  183.             $query="delete from clientes where id=$val";
  184.             $obj_usuario->executeQuery($query); // ejecuta la consulta para  borrar el cliente
  185.             return $query .'<br/>Registros afectados: '.$obj_usuario->getAffect(); // retorna todos los registros afectados
  186.    
  187.     }  
  188. }
  #6 (permalink)  
Antiguo 21/11/2011, 14:08
Avatar de linuxzero  
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

Postea el error, la linea del error y el codigo del archivo donde dice que aparece el error, porque ahi estas utilizando una clase Usuario y puede que el error este ahi, pero el primer post era otro codigo. Postea el codigo la linea donde tira el error y el error que te tira
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com
  #7 (permalink)  
Antiguo 21/11/2011, 14:09
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

por que pones $users en el mysql_fetch_array?

si la instancia es $usuarios= $usuario->getUsuarios();

$users no existe. por eso esta vacio :)
  #8 (permalink)  
Antiguo 22/11/2011, 12:07
 
Fecha de Ingreso: mayo-2010
Mensajes: 12
Antigüedad: 14 años
Puntos: 0
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

Hola y gracias!, corregí users por usuarios, pero sigue mostrando el mismo mensaje de error que postee en el título, algun consejo?

Gracias!

Código PHP:
Ver original
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body>
  6. <?php
  7. include_once ("clase.php"); // incluye las clases
  8.     $calle="";
  9.     $numero="";
  10.     $distrito="";
  11.     $departamento="";
  12.     $nombre="";
  13.     $apellido="";
  14.     $profesion="";
  15.     $telefono="";
  16.     $email="";
  17.     $dni="";
  18.     $usuario="";
  19.     $id="";
  20.  
  21. if (isset($_GET['md'])) // si la operacion es modificar, este valor viene seteado y ejecuta el siguiente codigo
  22. {
  23.     $usuario=new Usuario($_GET['md']);  // instancio la clase cliente pasandole el nro de cliente, de esta forma lo busca
  24.     $nombre=$usuario->getNombre();      // obtengo el nombre
  25.     $apellido=$usuario->getApellido();  // obtengo el apellido
  26.     $profesion =$usuario->getProfesion;
  27.     $telefono=$usuario->getTelefono;
  28.     $email=$usuario->getEmail;
  29.     $dni=$usuario->getDni;
  30.     $calle=$usuario->getCalle();
  31.     $numero=$usuario->getNumero();
  32.     $distrito=$usuario->getDistrito();
  33.     $departamento=$usuario->getDepartamento();
  34.     $id=$usuario->getId();              // obtengo el id
  35.  
  36. }
  37. ?>
  38.  
  39. <div >
  40. <form method="POST" action="usuarios.php">
  41. <input type="hidden" name="id" value="<?php print $id ?>">
  42. <table border=1>
  43.  
  44. <tr>
  45.     <td>Nombre</td>
  46.     <td><input type="text" name="nombre" value = "<?php print $nombre ?>"></td>
  47. </tr>
  48. <tr>
  49.     <td>Apellido</td>
  50.     <td><input type="text" name="apellido"value = "<?php print $apellido ?>"></td>
  51. </tr>
  52. <tr>
  53.     <td>Profesion</td>
  54.     <td><input type="text" name="profesion"value = "<?php print $profesion ?>"></td>
  55. </tr>
  56.  
  57. <tr>
  58.     <td>Telefono</td>
  59.     <td><input type="text" name="telefono"value = "<?php print $telefono ?>"></td>
  60. </tr>
  61. <tr>
  62.     <td>Email</td>
  63.     <td><input type="text" name="email"value = "<?php print $email ?>"></td>
  64. </tr>
  65. <tr>
  66.     <td>DNI</td>
  67.     <td><input type="text" name="dni"value = "<?php print $dni ?>"></td>
  68. </tr>
  69. <tr>
  70.     <td>Calle</td>
  71.     <td><input type="text" name="calle"value = "<?php print $calle ?>"></td>
  72. </tr>
  73. <tr>
  74.     <td>Numero</td>
  75.     <td><input type="text" name="numero"value = "<?php print $numero ?>"></td>
  76. </tr>
  77. <tr>
  78.     <td>Distrito</td>
  79.     <td><input type="text" name="distrito"value = "<?php print $distrito ?>"></td>
  80. </tr>
  81. <tr>
  82.     <td>Departamento</td>
  83.     <td><input type="text" name="departamento"value = "<?php print $departamento ?>"></td>
  84. </tr>
  85. <tr>
  86.     <td></td>
  87.     <td align =right><input type="submit" name="submit" value ="<?php if(is_numeric($id)) print "Modificar"; else print "Ingresar";?>"></td>
  88. </tr>
  89. </table>
  90. </form>
  91. </div>
  92. <?php
  93.  
  94.  
  95.  
  96.  
  97. if (isset($_POST['submit'])&&!is_numeric($_POST['id'])) // si presiono el boton ingresar
  98. {
  99.     $usuario=new Usuario();
  100.     //print_r($_POST);
  101.     $usuario->setNombre($_POST['nombre']); // setea los datos
  102.     $usuario->setApellido($_POST['apellido']); 
  103.     $usuario->setProfesion($_POST['profesion']);
  104.     $usuario->setTelefono($_POST['telefono']); 
  105.     $usuario->setEmail($_POST['email']);   
  106.     $usuario->setDni($_POST['dni']);   
  107.     $usuario->setCalle($_POST['calle']);   
  108.     $usuario->setNumero($_POST['numero']); 
  109.     $usuario->setDistrito($_POST['distrito']); 
  110.     $usuario->setDepartamento($_POST['departamento']); 
  111.     print " Consulta ejecutada: ". $usuario->insertUsuario(); // inserta y muestra el resultado
  112. }
  113. if (isset($_POST['submit'])&&is_numeric($_POST['id'])) // si presiono el boton y es modificar
  114. {
  115.     $usuario=new Usuario($_POST['id']);  // instancio la clase pasandole el nro de cliente para cargar los datos
  116.     $usuario->setNombre($_POST['nombre']); // setea los datos nuevos
  117.     $usuario->setApellido($_POST['apellido']); 
  118.     $usuario->setProfesion($_POST['profesion']);
  119.     $usuario->setTelefono($_POST['telefono']); 
  120.     $usuario->setEmail($_POST['email']);   
  121.     $usuario->setDni($_POST['dni']);   
  122.     $usuario->setCalle($_POST['calle']);   
  123.     $usuario->setNumero($_POST['numero']); 
  124.     $usuario->setDistrito($_POST['distrito']); 
  125.     $usuario->setDepartamento($_POST['departamento']); 
  126.     print " Consulta ejecutada: ". $usuario->updateUsuario(); // inserta y muestra el resultado
  127. }
  128. if (isset($_GET['br'])&&is_numeric($_GET['br'])) // si presiono el boton y es eliminar
  129. {
  130.     $usuario=new Usuario();
  131.     print " Consulta ejecutada: ". $usuario->deleteUsuario($_GET['br']); // elimina el cliente y muestra el resultado
  132. }
  133.  
  134.  
  135.  
  136. $usuario=new Usuario();
  137. $usuarios= $usuario->getUsuarios(); // obtiene todos los clientes para despues mostrarlos
  138.  
  139. print '<br/><br/><table border=1>'
  140.            .'<tr><td>Nombre:</td>'
  141.           .'<td>Apellido:</td>'
  142.           .'<td>Profesion</td>'
  143.           .'<td>Telefono</td>'
  144.           .'<td>Email</td>'
  145.           .'<td>DNI</td>'
  146.           .'<td>Calle</td>'
  147.           .'<td>Numero</td>'
  148.           .'<td>Distrito</td>'
  149.           .'<td>Departamento</td>'
  150.           .'<td>Modificar</td>'
  151.           .'<td>Borrar</td></tr>';
  152.  
  153. while ($row=mysql_fetch_array($usuarios)) // recorre los clientes uno por uno hasta el fin de la tabla
  154. {
  155.     print '<tr>'
  156.           .'<td>'.$row['nombre'] .'</td>'
  157.           .'<td>'.$row['apellido'] .'</td>'
  158.           .'<td>'.$row['telefono'] .'</td>'
  159.           .'<td>'.$row['email'] .'</td>'
  160.           .'<td>'.$row['dni'] .'</td>'
  161.           .'<td>'.$row['calle'] .'</td>'
  162.           .'<td>'.$row['numero'] .'</td>'
  163.           .'<td>'.$row['distrito'] .'</td>'
  164.           .'<td>'.$row['departamento'] .'</td>'
  165.           .'<td><a href="usuarios.php?md='.$row['id'].'">Modificar</a></td>'   // en este ejemplo para simplificar se envian los parametros por get utilizando un href
  166.           .'<td><a href="usuarios.php?br='.$row['id'].'">Borrar</a></td>'       // lo correcto seria enviarlos por post con un submit por ejem.
  167.           .'</tr>';
  168. }
  169. print '</table>';
  170. ?>
  171. </body>
  172. </html>
  #9 (permalink)  
Antiguo 22/11/2011, 12:20
Avatar de linuxzero  
Fecha de Ingreso: noviembre-2011
Ubicación: Argentina
Mensajes: 778
Antigüedad: 12 años, 5 meses
Puntos: 160
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

El contructor de tu clase Usuario es como el de java y no funciona asi, deberias usar el constructor de php que es __construct() y ahi utilizas el constructor.

Ademas para utilizarlo asi:

Código PHP:
Ver original
  1. $usuario = new Usuario($dato);
  2. $usuario->getNombre();

En la misma clase en el constructor tenes que devolver la instancia de la clase, para que puedas llamar a otro métodod desde la misma instancia, no se si me explico.
__________________
Si todo fuera tan sencillo como un symfony cc la vida seria más fácil.
http://phpnico.wordpress.com
  #10 (permalink)  
Antiguo 22/11/2011, 15:27
 
Fecha de Ingreso: julio-2010
Mensajes: 275
Antigüedad: 13 años, 10 meses
Puntos: 21
Respuesta: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean g

creo que estas utilizando xajax, deberias enseñar lo que haces en las funciones

print " Consulta ejecutada: ". $usuario->updateUsuario();
y
print " Consulta ejecutada: ". $usuario->insertUsuario(); // inserta y muestra el resultado

o en su defecto, revisar esos métodos... si usas xajax y el modelo vista-controlador deberías tener una carpeta llamada clases, donde están los objetos a los que haces referencia.

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más 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 18:52.