El if
Código PHP:
$page_mode = base64_decode($_GET[mode]);
if ($page_mode == "")
{
$page_mode = "id";
}else{
$page_mode = "base64_decode($_GET[mode])";
}
Código PHP:
<html>
<head>
<title></title>
<link href="styles/crystal.css" rel="stylesheet" type="text/css">
</head>
<body class="body">
<div class="div_container">
<div class="div_title">Base de Datos</div>
<div class="div_text">
<?
$dbhost='localhost';
$dbusername='root';
$dbuserpass='xxxx';
$dbname='xxxx';
$con=mysql_connect($dbhost,$dbusername,$dbuserpass);
mysql_select_db($dbname,$con);
if (!isset($pg))
$pg = 0; // $pg es la pagina actual
$cantidad = 12; // cantidad de resultados por página
$inicial = $pg * $cantidad;
$page_mode = base64_decode($_GET[mode]);
if ($page_mode == "")
{
$page_mode = "id";
}else{
$page_mode = "base64_decode($_GET[mode])";
}
$pegar = "SELECT * FROM users ORDER BY "$page_mode"";
$cad = mysql_db_query($dbname,$pegar) or die (mysql_error());
$contar = "SELECT * FROM users ORDER BY "$page_mode"";
$contarok= mysql_db_query($dbname,$contar);
$total_records = mysql_num_rows($contarok);
$pages = intval($total_records / $cantidad);
$color= "#D4D4D4";
$style="font-family:Arial, Helvetica, sans-serif; font-size:12px; font-weight:bold;";
// Imprimiendo los resultados
echo "<table class='table'>
<tr class='tr'>";
$mode = "id";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>ID</a></td>";
$mode = "username";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Nombre</a></td>";
$mode = "age";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Edad</a></td>";
$mode = "sex";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Genero</a></td>";
$mode = "marital";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>E. Civil</a></td>";
$mode = "preference";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Pref. Sexual</a></td>";
$mode = "location";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Ubicación</a></td>";
$mode = "email";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>E-mail</a></td>";
$mode = "website";
echo " <td bgcolor='".$color."' style='".$style."'><a href='view.php?mode=".base64_encode($mode)."'>Sitio Web</a></td>
</tr>";
while($array = mysql_fetch_array ($cad)) {
if ($colorfila==0){
$color= "#EAEAEA";
$style="font-family:Arial, Helvetica, sans-serif; font-size:12px;";
$colorfila=1;
}else{
$color="#F1F1F1";
$style="font-family:Arial, Helvetica, sans-serif; font-size:12px;";
$colorfila=0;
}
echo "<tr bgcolor='".$color."' style='".$style."' onmouseover=\"this.style.background='#FFFFFF'\" onmouseout=\"this.style.background='".$color."'\">
<td>".$array['id']."</td>
<td>".$array['username']."</td>
<td>".$array['age']."</td>
<td>".$array['sex']."</td>
<td>".$array['marital']."</td>
<td>".$array['preference']."</td>
<td>".$array['location']."</td>
<td><a style='text-decoration:none' href='mailto:".$array['email']."'>".$array['email']."</td>
<td><a style='text-decoration:none' target='_blank' href='".$array['website']."'>".$array['website']."</td>
</tr>";
}
echo "</table>";
// Cerramos la conexión a la base
$con=mysql_close($con);
// Creando los enlaces de paginación
//echo "<p>";
//if ($pg <> 0)
//{
//$url = $pg - 1;
//echo "<a href='alternarcolores.php?pg=".$url."'>« Anterior</a> ";
//}
//else {
//echo " ";
//}
//for ($i = 0; $i<($pages + 1); $i++) {
//if ($i == $pg) {
//echo "<font face=Arial size=2 color=ff0000><b> $i </b></font>";
//}
//else {
//echo "<a href='alternarcolores.php?pg=".$i."'>".$i."</a> ";
//}
//}
//if ($pg < $pages) {
//$url = $pg + 1;
//echo "<a href='alternarcolores.php?pg=".$url."'>Siguiente »</a>";
//}
//else {
//echo " ";
//}
//echo "</p>";
?>
</div>
</div>
</body>
</html>
Gracias.