He mirado de hacer un javascript con php para que pueda mostrar/ocultar menu, categorías pero veo que al refrescar la página pierdo todo los valores del javascript y me se oculta todo.
Como puedo hacer que se muestre en php, refrescando la página?
Código PHP:
<?
$conexion = mysql_connect("localhost","xxxxxxx","xxxxxxxxxxx");
mysql_select_db(xxxxxxxxxx,$conexion);
?>
<!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" lang="en" xml:lang="en">
<head>
<title>Prueba</title>
<?
# Carga desde php
if ($_GET[id])
{
}
?>
<script languaje="Javascript" type="text/javascript">
document.write('<style type="text/css">div.ocultable{display: none;}</style>');
function MostrarOcultar(capa,enlace)
{
if (document.getElementById)
{
var aux = document.getElementById(capa).style;
aux.display = aux.display? "":"block";
}
}
</script>
</head>
<body>
<table width="20%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30" align="center" valign="middle" bgcolor="#CCCCCC">
<a href="javascript:MostrarOcultar('idMenu');">
<strong>MENU</strong>
</a>
</td>
</tr>
<tr>
<td>
<div class="ocultable" id="idMenu">
<?php
$registros=mysql_query("select * from servicios_cat ORDER BY ordenado ASC",$conexion);
while($reg=mysql_fetch_array($registros))
{
?>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td bgcolor="#f1f1f1"><!-- ROSA gris -->
<a href="javascript:MostrarOcultar('id<?= $reg['texto_1'];?>');">
<strong>• <?php echo $reg['texto_1']; ?></strong>
</a>
</td>
</tr>
</table>
<div class="ocultable" id="id<?= $reg['texto_1'];?>">
<table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#f9f9f9"><!-- ROSA -->
<?php
$COD=$_REQUEST['cod_sub_cat'];
//$CATEGORIA=$_REQUEST['categoria'];
$registros2=mysql_query("select * from servicios_sub where id_compras_cat='".$reg[id]."'",$conexion);
while($reg2=mysql_fetch_array($registros2))
{
?>
<tr>
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td><!-- AZUL claro -->
<a href="?id=<?= $reg2['id']; ?>">
<?php echo $reg2['textosub_1']; ?>
</a>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
</table>
</div>
<?php
}
?>
</div>
</td>
</tr>
</table>
</body>
</html>