Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/01/2013, 11:02
Avatar de informacionsys
informacionsys
 
Fecha de Ingreso: mayo-2011
Ubicación: Bogota D.C
Mensajes: 793
Antigüedad: 13 años
Puntos: 76
Respuesta: Aplicar css a enlace activo de menu dinàmico a partir de registros de tabl

Podrias usar Jquery

Código PHP:
Ver original
  1. <?php require_once('Connections/conexion.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $colname_section_lang = "-1";
  35. if (isset($_GET['id_lang'])) {
  36.   $colname_section_lang = $_GET['id_lang'];
  37. }
  38. mysql_select_db($database_conexion, $conexion);
  39. $query_section_lang = sprintf("SELECT mc_section_lang.id, mc_section_lang.id_section, mc_section_lang.id_lang, mc_section_lang.section_lang  FROM mc_section_lang WHERE id_lang = %s AND id_section >3", GetSQLValueString($colname_section_lang, "int"));
  40. $section_lang = mysql_query($query_section_lang, $conexion) or die(mysql_error());
  41. $row_section_lang = mysql_fetch_assoc($section_lang);
  42. $totalRows_section_lang = mysql_num_rows($section_lang);
  43. ?>
  44. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  45. <html xmlns="http://www.w3.org/1999/xhtml">
  46. <head>
  47. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  48. <title>menu</title>
  49. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  50. <script type="text/javascript">
  51.     $(function()
  52.     {
  53.        $(".links").click(function()// en evento click de cada enlace con la clase .links
  54.        {  
  55.           $(".links").removeClass("active");//quito la clase active de todos los demas links
  56.           $(this).addClass("active");// añado la clase active al enlace clickeado
  57.        });
  58.     })
  59. </script>
  60.  
  61. <style type="text/css">
  62. .active {
  63.     font-style: italic;
  64.     font-weight: bold;
  65.     text-transform: uppercase;
  66.     color: #F00;
  67.     text-decoration: none;
  68. }
  69. </style>
  70. </head>
  71.  
  72. <body>
  73.  
  74. <div id="submenu">
  75. <ul>
  76. <?php do { ?>
  77.   <li><a class="links" href="?id_section=<?php echo $row_section_lang['id_section']; ?>&id_lang=<?php echo $row_section_lang['id_lang']; ?>"><?php echo $row_section_lang['section_lang']; ?></a></li>
  78.   <?php } while ($row_section_lang = mysql_fetch_assoc($section_lang)); ?>
  79. </ul>
  80. </div>
  81.  
  82. </body>
  83. </html>
  84. <?php
  85. mysql_free_result($section_lang);
  86. ?>