Comunidad de diseño web y desarrollo en internet online

duda php - mysql / listar datos base datos

Citar            
MensajeEscrito el 28 Ene 2007 06:30 pm
hola,
alguien podria indicarme como mostrar por pantalla un dato de una base datos. mi codigo es el siguiente.
-------------------------------------------

Código :

<?php
$query = "SELECT nombre FROM Usuario
ORDER BY nombre";
$result=mysql_query($query) or die(mysql_error()); 

$row = mysql_fetch_row($result);
?>

-------------------------------------------
Necesito mostrar por pantalla el "nombre" de la tabla Usuario. No se cual es la variable que guarda el valor ni como llamarla.
Gracias y saludos.

Por feix

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Ene 2007 06:47 pm
Hola,

prueba esto:

Código :

<?php
$query = "SELECT nombre FROM Usuario ORDER BY nombre";
$result=mysql_query($query) or die(mysql_error());

while ($row = mysql_fetch_row($result)) {
    echo $row['nombre'];  // tb puedes poner echo $row[0]
}
?> 


Saludos!

Por dmvalverde

150 de clabLevel



Genero:Masculino  

Extremadura

firefox
Citar            
MensajeEscrito el 28 Ene 2007 07:02 pm
Muchas gracias. He avanzado algo, aunque ahora me lista todos los datos "nombre" de la tabla.

Saludos.

Por feix

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Ene 2007 08:06 pm
No era eso lo que querias?

Por dmvalverde

150 de clabLevel



Genero:Masculino  

Extremadura

firefox
Citar            
MensajeEscrito el 28 Ene 2007 08:11 pm
No. Se se supone que la pagina anterior ha validado un usuario y contraseña y en esta segunda debe dar la bienvenida al usuario nombre validado.
El codigo de la primera pagina es:

Código :

<?php

if ($_POST['usuario'] && $_POST['pwd'])
{  
   $link = mysql_connect('localhost', 'root', '')
      or die('Could not connect: ' . mysql_error());
      
   mysql_select_db('portal') or die('Could not select database');
   
   // Performing SQL query
   $query = "SELECT nombre,pwd FROM usuario where nombre='".$_POST['usuario']."'";
   $result = mysql_query($query) or die('Query failed: ' . mysql_error());
      
  $row = mysql_fetch_row($result);
   
   if ($_POST['pwd']==$row['1']) 
   {
      echo "hola ".$_POST['usuario'];
      $usuari_session=0;
      echo "<script>document.location.href='1.php'</script>";
   }
         $error= "Usuario incorrecto!!  Prueba de nuevo...";
      }
?>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><link rel="STYLESHEET" type="text/css" href="estilos.css">
<title>ACCESO EMPLEADOS</title>
</head><big>ACCESO EMPLEADOS</big><hr /><?php echo gmdate ("d / n / y"); ?>
<body>
<blockquote>
<fieldset title="Accede a Gestion de empleados.">
<legend>Administracion Empleados</legend>

<form method="post" action="20.php">
<table border="0" cellpadding="4" cellspacing="2">
   <tbody><tr>
      <td><label for="usuario">Usuario:</label></td>
      <td><input name="usuario" id="usuario" type="text"></td>
   </tr>
   <tr>
      <td><label for="Password">Password: </label></td>
      <td><input name="pwd" id="pwd" type="password"></td>
   </tr>
   <tr>
      <td></td>
      <td><input name="enviar" id="enviar" value="Aceptar" type="submit"></td>
   </tr>
</form>
<tr>
      <td></td>
      <td><?php echo $error ?></td>
   </tr>
</tbody>
</table>
</fieldset>
</body>
</html>
<?php

?>



y en la segunda pagina:

Código :

<?php require("global.php")?>
<?php

$query = "SELECT nombre FROM Usuario 
ORDER BY nombre";

$result=mysql_query($query) or die(mysql_error()); 
$row = mysql_fetch_array($result);?>


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ACCESO</title>
</head><link rel="STYLESHEET" type="text/css" href="estilos.css"><big>AREA PERSONAL<br /></big><i>Bienvenido Sr 

<?php
while ($row = mysql_fetch_row($result)) {
    echo $row['0']; 
}
?> 

</i><hr />
<br /><br /><a id="x"/>
<body><br /><br />
<center>
<blockquote>
<form method="post" action="2.php">
<tr>
<td></td>         
<td><input name="datosperso" title="Datos personales" type="submit" value="Datos Personales" /></a><br /></td>
</tr>
</form><br />

<form method="post" action="3.php">
<input name="ultinomina" title="Ultima nomina" type="submit" value="Ultimas nominas" /></a><br />
</form><br />
<form method="post" action="4.php">
<input name="beneficios" title="Solicitud y gestion de beneficios" type="submit" value="Solicitud y Gestion de Beneficios" /></a><br />
</form><br />

</blockquote>
</center>
<form method="post" action="20.php">
   <tr>
      <td></td>
      <td><input id="submit" title="Desconexion" type="submit"value="Desconectar"></td>
   </tr>
</form>
</body>
</html>



[BOFH] Por Keyra, te conjuro a que aprendas a utilizar la etiqueta [ code ] [ / code ], encerrando entre sus pespectivos inicio y fin tu código....[/BOFH]

Por feix

2 de clabLevel



 

firefox
Citar            
MensajeEscrito el 28 Ene 2007 08:21 pm
ok. En este caso debes modificar la sentencia SQL con una cláusula WHERE donde le pases el nombre del usuario que validastes en la primera página. Para obtener ese nombre, normalmente se utilizan sesiones

Por dmvalverde

150 de clabLevel



Genero:Masculino  

Extremadura

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.