Ver Mensaje Individual
  #13 (permalink)  
Antiguo 18/08/2012, 13:37
Avatar de corh861212
corh861212
 
Fecha de Ingreso: julio-2012
Ubicación: en el estado de mexico
Mensajes: 12
Antigüedad: 11 años, 9 meses
Puntos: 3
Respuesta: Problema con mostrar los datos de MySql en una TABLA con PHP

hola creo que esto es mas facil son datos de una base de datos mostrados en una tabla php fasilmente con un while
Código PHP:
$dbhost='localhost'// Servidor
$dbusername='daniel'// Nombre de usuario
$dbuserpass=''// Contraseña
$dbname='punto'// Nombre de la base de datos

$link=mysql_connect($dbhost,$dbusername,$dbuserpass);
mysql_select_db($dbname)or die('no se puede seleccionar la base de datos'); 
Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns2="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Punto de venta HDCR</title>
<link rel="stylesheet" type="text/css" href="stylemedic.css" media="screen" />
</head>
<body>
<div id="main_content">
<div id="iframe2">
[PHP]
<?
$resultado=mysql_query("SELECT * FROM producto",$link);
echo"
<table border='0'id='mi_tabla'>
<thead>
<tr> <td colspan='8'> Buscar <input id='filtrar' type='text' /></td><td colspan='5'><button onclick='salir(this)'accesskey='p'type='submit'>Salir</button></td></tr>
<tr>
<th><></th>
<th>CODIGO</th>
<th>DESCRIPCION</th>
<th>COSTO</th>
<th>VENTA</th>
<th>EXISTENCIAS</th>
<th>DIA</th>
<th>MES</th>
<th>A&ntilde;o</th>
</tr>
</thead>";
echo "<tbody>";
//ojo aqui esta el bucle que mustra los datos
while ($campo= mysql_fetch_row($resultado)){
$fecha=explode ("-",$campo[7]);
echo"<tr style='cursor:pointer' class='desmarcado' onclick='muestra(this)' >";
echo"<td>".$campo[1]."</td>";
echo"<td>".$campo[2]."</td>";
echo"<td>".$campo[3]."</td>";
echo"<td>".$campo[4]."</td>";
echo"<td>".$campo[5]."</td>";
echo"<td>".$campo[6]."</td>";
echo"<td>".$fecha[2]."</td>";
echo"<td>".$fecha[1]."</td>";
echo"<td>".$fecha[0]."</td>";
echo"</tr>";
}
echo"</tbody>";
echo "</table>";
?>
[/PHP]
</div>
</div> 
Y basicamente lo que esto hace ES MOSTRAR TODOS TUS REG DE TU BASE DE DATOS EN UNA TABLA QUE ES CREADA DINAMICAMENTE
pon esto en el css para que sea de dos colores la tabla
Código CSS:
Ver original
  1. table {
  2.             border: 1px solid gray;
  3.             border-radius: 2px;
  4.             width: 700px; /* Ancho fijo para que no cambie cuando se filtra */
  5.        
  6.         }
  7.        
  8.         table thead {
  9.             color: white;
  10.             background: silver;
  11.         }
  12.        
  13.        
  14.         table tbody tr:nth-child(odd){
  15.         background-color: #E0E0F8;
  16.         color:#151515;
  17.         }
  18.        
  19.         table tbody tr:nth-child(even){
  20.         background-color: #D8D8D8;
  21.         color:#B40404;
  22.         }
  23.  
  24.    
  25.        
  26.         table thead input[type="text"] {
  27.             float: right;
  28.         }
  29.        
  30.         table td {
  31.             border: 1px solid gray;
  32.             padding: 2px 4px;
  33.             border-radius: 2px;
  34.         }

Última edición por corh861212; 18/08/2012 a las 13:49