Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/10/2010, 12:14
agoraestudio
 
Fecha de Ingreso: marzo-2010
Mensajes: 61
Antigüedad: 14 años, 1 mes
Puntos: 1
Respuesta: seleccionar una tabla para cargar su contenido

Cita:
Iniciado por blonder413 Ver Mensaje
yo hago esto para ordenar una tabla, pero bien podrian cambiarse los valores y la consulta para elegir otra

Código:
<?php
require_once("conexion.php");
?>
<html>
<head>
<title>Ingreso de Empleados</title>
<style type="text/css">
<!--
.Estilo1 {
	font-size: 36px;
	font-weight: bold;
	color: #669900;
}
.Estilo2 {font-size: 36px; font-weight: bold; color: #0000CC; }
.Estilo3 {
	font-size: 18px;
	font-weight: bold;
	color: #0000CC;
}
.Estilo5 {font-size: 18px; font-weight: bold; color: #669900; }
.Estilo6 {font-size: 24px}
-->
</style>

<style type="text/css">
	.encabezado{ background-color:#666666; color:#FFFFFF; font-weight:bold}
	.registros{ background-color:#f0f0f0}
</style>
<script language="javascript" type="text/javascript">
	function eliminar(cedula)
	{
		if (confirm("Realmente desea eliminar el registro?"))
		{
			window.location="eliminarempleado.php?cedula="+cedula;
		}
	}
	
	function defaul_combo(){
	<?php
		if(isset($_GET["ordena"])){
	?>
			document.orden.ordena.tabindex=".$_GET["ordena"].";
	<?php
		}else{
	?>
			document.orden.ordena.tabindex="cedula";
	<?php
		}
	?>
	}
	
</script>


</head>

<body>
<table width="715" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td width="715" height="124" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="217" height="124" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="217" height="124" valign="top"><img src="imagenes/logo.jpg" width="178" height="106"></td>
          </tr>
        </table>        </td>
        <td width="498" valign="top"><p align="center" class="Estilo2">Control </p>
          <p align="center" class="Estilo1">Material de Proteccion </p></td>
      </tr>
    </table>    </td>
  </tr>

<td height="171" valign="top">
<table width="700" align="center">
<tr>
<td valign="top" align="center" width="700" colspan="5">
<h3>Listado de empleados</h3>
</td>
</tr>
<tr>
<td valign="top" align="center" width="700" colspan="5">
	<form name="orden" action="ordenlista.php" method="get">
		<select name="ordena" title="Seleccione el criterio por el que desea ordenar">
			<option value="cedula">C&eacute;dula</option>
			<option value="nombre">Nombre</option>
			<option value="apellido1">Apellidos</option>
			<option value="fechaingreso">Fecha de ingreso</option>
		</select>&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="submit" value="Ordenar" title="Clic para Ordenar">
	</form>
</td>

</tr>

<tr class="encabezado">
<td valign="middle" align="center" width="70">Cedula</td>
<td valign="middle" align="center" width="170">Nombres</td>
<td valign="middle" align="center" width="120">Primer Apellido</td>
<td valign="middle" align="center" width="120">Segundo Apellido</td>
<td valign="middle" align="center" width="120">Fecha de Ingreso</td>
<td valign="middle" align="center" width="25">&nbsp;</td>
<td valign="middle" align="center" width="25">&nbsp;</td>
</tr>

<?php
$sql="SELECT * FROM empleado ORDER BY ".$_GET["ordena"]."";
$res=mysql_query($sql,$con);
while ($reg=mysql_fetch_array($res))
{
?>
<tr class="registros">
<td valign="middle" align="left" width="70"><?php echo $reg["cedula"]; ?> </td>
<td valign="middle" align="left" width="170"><?php echo $reg["nombre"]; ?> </td>
<td valign="middle" align="left" width="120"><?php echo $reg["apellido1"]; ?> </td>
<td valign="middle" align="left" width="120"><?php echo $reg["apellido2"]; ?> </td>
<td valign="middle" align="left" width="120"><?php echo $reg["fechaingreso"]; ?> </td>
<td valign="middle" align="left" width="25">
<a href="modificarempleado.php?cedula=<?php echo $reg["cedula"];?>" title="Modificar"><img src="ima/editar.png" border="0"></a>
</td>
<td valign="top" align="center" width="25">
<a href="javascript:void(0)" title="Eliminar" onClick="eliminar('<?php echo $reg["cedula"];?>')"><img src="ima/eliminar.png" border="0"></a>
</td>
</tr>
<?php
}	//cierre mysql_fetch_array
mysql_close($con);	//cierra la conexión a la base de datos
?>
<tr>
<td valign="top" align="right" width="700" colspan="5">
  <div align="center"><a href="index.html" title="Regresar"><img src="ima/regresar.png" width="103" height="44" border="0"></a>
    <a href="agregar.php" title="Agregar Empelados"><img src="ima/add48x48.png" border="0"></a></div></td>
</tr>

</table>
</body>
</html>

hola.. me he puesto a hacerlo de esta manera... y me da un error en :

while ($reg=mysql_fetch_array($res)) y no encuentro pq.. voy a pegar el codigo a ver si veis algo..



<?php
require_once("conex.php");
?>
<html>
<head>
<title>Ingreso de Empleados</title>
<style type="text/css">
<!--
.Estilo1 {
font-size: 36px;
font-weight: bold;
color: #669900;
}
.Estilo2 {font-size: 36px; font-weight: bold; color: #0000CC; }
.Estilo3 {
font-size: 18px;
font-weight: bold;
color: #0000CC;
}
.Estilo5 {font-size: 18px; font-weight: bold; color: #669900; }
.Estilo6 {font-size: 24px}
-->
</style>

<style type="text/css">
.encabezado{ background-color:#666666; color:#FFFFFF; font-weight:bold}
.registros{ background-color:#f0f0f0}
</style>
<script language="javascript" type="text/javascript">
function eliminar(cedula)
{
if (confirm("Realmente desea eliminar el registro?"))
{
window.location="eliminarempleado.php?cedula="+ced ula;
}
}

function defaul_combo(){
<?php
if(isset($_GET["ordena"])){
?>
document.orden.ordena.tabindex=".$_GET["ordena"].";
<?php
}else{
?>
document.orden.ordena.tabindex="cedula";
<?php
}
?>
}

</script>


</head>

<body>
<table width="715" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="715" height="124" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="217" height="124" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="217" height="124" valign="top"><img src="imagenes/logo.jpg" width="178" height="106"></td>
</tr>
</table> </td>
<td width="498" valign="top"><p align="center" class="Estilo2">Control </p>
<p align="center" class="Estilo1">Material de Proteccion </p></td>
</tr>
</table> </td>
</tr>

<td height="171" valign="top">
<table width="700" align="center">
<tr>
<td valign="top" align="center" width="700" colspan="5">
<h3>Listado de empleados</h3>
</td>
</tr>
<tr>
<td valign="top" align="center" width="700" colspan="5">
<form name="ordena" action="ordenlista.php" method="get">
<select name="tabla">
<option value="ninguna" selected="selected">SELECCION</option>
<option value="associazioni_imprese">Associazioni imprese</option>
<option value="banche">Banche</option>
<option value="confidi">Confidi</option>
<option value="credito_alle_imprese">Credito alle imprese</option>
<option value="crisi_d_impresa"> Crisi d'impresa</option>
<option value="derivati">Derivati</option>
<option value="private_equity">Private Equity</option>
<option value="settori_e_distretti">Settori e Distretti</option>
<option value="turnaround">Turnaround</option>
<option value="cosa_dicono">Cosa dicono</option>
</select>&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="ordena" title="Clic para Ordenar">
</form>
</td>

</tr>

<tr class="encabezado">
<td valign="middle" align="center" width="70">Cedula</td>
<td valign="middle" align="center" width="170">Nombres</td>
<td valign="middle" align="center" width="120">Primer Apellido</td>
<td valign="middle" align="center" width="120">Segundo Apellido</td>
<td valign="middle" align="center" width="120">Fecha de Ingreso</td>
<td valign="middle" align="center" width="25">&nbsp;</td>
<td valign="middle" align="center" width="25">&nbsp;</td>
</tr>

<?php
$link=Conectarse();
$sql="SELECT id,titulo,ruta FROM ".$_GET["ordena"]."";
$res=mysql_query($sql,$link);
while ($reg=mysql_fetch_array($res))
{
?>
<tr class="registros">
<td valign="middle" align="left" width="70"><?php echo $reg["id"]; ?> </td>
<td valign="middle" align="left" width="170"><?php echo $reg["titulo"]; ?> </td>
<td valign="middle" align="left" width="120"><?php echo $reg["ruta"]; ?> </td>
<td valign="middle" align="left" width="25">
<a href="modificarempleado.php?cedula=<?php echo $reg["cedula"];?>" title="Modificar"><img src="ima/editar.png" border="0"></a>
</td>
<td valign="top" align="center" width="25">
<a href="javascript:void(0)" title="Eliminar" onClick="eliminar('<?php echo $reg["cedula"];?>')"><img src="ima/eliminar.png" border="0"></a>
</td>
</tr>
<?php
} //cierre mysql_fetch_array
mysql_close($link); //cierra la conexión a la base de datos
?>
<tr>
<td valign="top" align="right" width="700" colspan="5">
<div align="center"><a href="index.html" title="Regresar"><img src="ima/regresar.png" width="103" height="44" border="0"></a>
<a href="agregar.php" title="Agregar Empelados"><img src="ima/add48x48.png" border="0"></a></div></td>
</tr>

</table>
</body>
</html>




muchas gracias!!