Foro de elhacker.net

Programación => Desarrollo Web => Mensaje iniciado por: MiguelDidac en 25 Enero 2014, 12:43 pm



Título: Como filtrar un dato con Ajax después de un "...?recordID=..."
Publicado por: MiguelDidac en 25 Enero 2014, 12:43 pm
Hola buenas,
Lo primero decir que este es mi primer trabajo de como hacer una web.
El caso es que no encuentro la manera de filtrar un dato como "ciudad" en el cual insertaré 18 ciudades, después de una página ya filtrada por "coches" que logrado a través  de un  "...?recordID=..." de forma que así me filtra por la marca del coche.
Ahora lo que quiero es filtrar por la cuidad del coche, a ser posible por Ajax.
Como verán soy muy inexperto en esto.
Muchas gracias de antemano.


Título: Re: Como filtrar un dato con Ajax después de un "...?recordID=..."
Publicado por: EFEX en 25 Enero 2014, 22:25 pm
Si te entendi bien... se puede enviar mas de un parametro...

Citar
?recordID=ford&ciudad=lacapital

Y sino expone lo que llevas hasta ahora y explicate un poco mas.
Saludos


Título: Re: Como filtrar un dato con Ajax después de un "...?recordID=..."
Publicado por: MiguelDidac en 26 Enero 2014, 07:38 am
Hola Efex,
ante todo muchas gracias por responder y tienes toda la razón: me expliqué muy poquito.
Bueno aquí te envío el código, como verás esta página ya viene precedida de otra y en principio sólo he puesto las primeras seis ciudades, ya pondré las demás.
Eso si, si tienes alguna idea mejor... ni que decir tiene que acepto sugerencias, he hecho unos tutoriales y llevo unos tres meses y a ratos con esto de programar.
Gracias otra vez.
Saludos.
Código
  1. <?php require_once('Connections/conexioncreacion.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. $varAnno_DatosDatosMarcas = "0";
  35. if (isset($_GET["anno"])) {
  36.  $varAnno_DatosMarcas = $_GET["anno"];
  37. }
  38. mysql_select_db($database_conexioncreacion, $conexioncreacion);
  39. $query_DatosMarcas = sprintf("SELECT * FROM tblmarcas WHERE tblmarcas.strmodelo = %s ORDER BY tblmarcas.intOrden ASC", GetSQLValueString($varAnno_DatosDatosMarcas, "text"));
  40. $DatosMarcas = mysql_query($query_DatosMarcas, $conexioncreacion) or die(mysql_error());
  41. $row_DatosMarcas = mysql_fetch_assoc($DatosMarcas);
  42. $totalRows_DatosMarcas = mysql_num_rows($DatosMarcas);
  43.  
  44.  
  45. ?>
Código
  1. <!DOCTYPE html>
  2. <html class="no-js"><!-- InstanceBegin template="/Templates/plantillabase.dwt.php" codeOutsideHTMLIsLocked="false" --> <!--<![endif]-->
  3.        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  4.        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">      
  5. <!-- InstanceBeginEditable name="doctitle" -->
  6. <title>Documento sin título</title>
  7. <script src="js/jquery-1.6.1.min.js" type="text/javascript" charset="utf-8"></script>
  8. <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
  9. <script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
  10. <!-- InstanceEndEditable -->
  11. <!-- InstanceBeginEditable name="head" -->
  12. <!-- InstanceEndEditable -->
  13. <link href="css/estiloprincipal.css" rel="stylesheet" type="text/css" />
  14. <link rel="stylesheet" href="css/menu.css" type="text/css" />
  15. <link rel="stylesheet" href="css/style.css">
  16. <link href='http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
  17. <link href='http://fonts.googleapis.com/css?family=Dosis:400,300,700' rel='stylesheet' type='text/css'>
  18.  
  19. <script src="js/libs/modernizr-2.5.3-respond-1.1.0.min.js"></script>
  20.  
  21. <?php include("includes/google.php"); ?>
  22. </head>
  23.  
  24. <div class="container">
  25. <div class="header-container">
  26. <div class="header">
  27.            <header class="wrapper clearfix">
  28.                <?php include("includes/cabecera.php"); ?>
  29.                <nav>
  30.                    <?php include("includes/menu.php"); ?>
  31.                </nav>
  32.            <!-- InstanceBeginEditable name="EditRegion5" --><!-- InstanceEndEditable --> </header>
  33.        </div>
  34. </div>
  35. <div class="main-container">
  36.  
  37.  <div class="sidebar1"><!-- InstanceBeginEditable name="ContenidoIzq" -->
  38.    <script type="text/javascript" charset="utf-8">
  39.  $(document).ready(function(){
  40.    $("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});
  41.  });
  42.  <p>&nbsp;</p>
  43.    <h1>Elige tu <?php echo $_GET["anno"]; ?></h1>
  44.  
  45.  
  46.    <p>A continuaci&oacute;n, presentamos una lista de los mejores coches.</p>
  47.  
  48.   <?php do { ?>    
  49.    <div class="ofertas1"><a href="images/marcas/<?php echo $row_DatosMarcas['strImagen']; ?>" rel="prettyPhoto[marcas_galeria]"><img src="images/marcas/<?php echo $row_DatosMarcas['strImagen']; ?>" width="200" alt="<?php echo $row_DatosMarcas['strTitulo']; ?>" /></a><br /><?php echo $row_DatosMarcas['strTitulo']; ?>
  50.      <br />
  51.      <a href="<?php echo $row_DatosMarcas['strLink']; ?>" target="_blank">Visitar Web</a> - <a href="marcas_informacion.php?idweb=<?php echo $row_DatosMarcas['intContador']; ?>">Ver informaci&oacute;n</a></div>
  52.    <?php } while ($row_DatosMarcas = mysql_fetch_assoc($DatosMarcas)); ?>
  53.  
  54.       <!-- InstanceEndEditable --><!-- end .sidebar1 --></div>
  55.  <!-- InstanceBeginEditable name="ParteDerecha" -->
  56.  <p>&nbsp;</p>
  57.  <div class="content">
  58.    <h1>Poblaci&oacute;n</h1>
  59.    <p>Seleccione la poblaci&oacute;n donde quiere ver su coche.</p>
  60.  
  61.  <p>&nbsp;</p>
  62.  
  63.  <ul>
  64.     <table width="300"  align="left" cellpadding="0">
  65.  
  66.  
  67.  <tr>
  68.    <th width="100" height="25">
  69.    <a href="marcas_poblacion.php?anno=">Alaquas</a></th>
  70.    <th width="100"><a href="marcas_poblacion.php?anno=Albal<?php echo $row_DatosMarcas['strModelo']; ?>">Albal</a></th>
  71.    <th width="100"><a href="marcas_poblacion.php?ciudad=Alfafar">Alfafar</a></th>
  72.    <th width="100"><a href="marcas_poblacion.php?ciudad=Anna">Anna</a></th>
  73.    <th width="100"><a href="marcas_poblacion.php?ciudad=Benetusser">Benetusser</a></th>
  74.    <th width="100"><a href="marcas_poblacion.php?ciudad=Catarroja">Catarroja</a></th>
  75.    </tr>
  76.    </table>
  77.    </ul>
  78. </div>  
  79.    <!-- end .content -->
  80.  <!-- InstanceEndEditable -->
  81.  <div class="footer">
  82.  <?php include("includes/pie.php"); ?></div>
  83.  <!-- end .container --></div>
  84.  </div>
  85. </body>
  86. <!-- InstanceEnd --></html>
  87. <?php
  88. mysql_free_result($DatosMarcas);
  89.  
  90. ?>

NOTA MOD: USAR GESHI PARA CODIGOS [code=html4strict][/code], [code=php][/code]. Existe boton modificar para modificar posts (https://foro.elhacker.net/Themes/converted/images/spanish/modify.gif).


Título: Re: Como filtrar un dato con Ajax después de un "...?recordID=..."
Publicado por: EFEX en 26 Enero 2014, 22:35 pm
Código
  1. $(document).ready(function(){
  2. $('th a').on('click', function(event){ //al hacer click en el enlace de la tabla...
  3. var enlace = $(this).attr('enlace'); //obtenemos la direccion..
  4.  
  5. $.ajax({url:enlace, dataType:"html", //definimos el archivo php que llamaremos y tipo de datos
  6. success:function( data ){ //si tuvo exito lo mostramos.
  7. $(".showtime").html( data );
  8. }
  9. });
  10.  
  11. event.stopPropagation();
  12. });
  13. });
  14.  

Cambiando un poco el html..

Código
  1. <div class="showtime">Aqui se muestran los resultados..</div>
  2. <hr>
  3. <ul>
  4. <table width="300"  align="left" cellpadding="0">
  5. <tr>
  6. <th width="100" height="25"><a href="#" enlace="marcas_poblacion.php?anno=Alaquas">Alaquas</a></th>
  7. <th width="100"><a href="#" enlace="marcas_poblacion.php?anno=Albal">Albal</a></th>
  8. <th width="100"><a href="#" enlace="marcas_poblacion.php?ciudad=Alfafar">Alfafar</a></th>
  9. <th width="100"><a href="#" enlace="marcas_poblacion.php?ciudad=Anna">Anna</a></th>
  10. <th width="100"><a href="#" enlace="marcas_poblacion.php?ciudad=Benetusser">Benetusser</a></th>
  11. <th width="100"><a href="#" enlace="marcas_poblacion.php?ciudad=Catarroja">Catarroja</a></th>
  12. </tr>
  13. </table>
  14. </ul>
  15.  

Ajax
http://api.jquery.com/jQuery.ajax/


Era eso?


Título: Re: Como filtrar un dato con Ajax después de un "...?recordID=..."
Publicado por: MiguelDidac en 27 Enero 2014, 22:44 pm
Hola EFEX,

Estoy comprobando lo que me enviaste, hoy la verdad es que apenas he tenido tiempo debido a unos asuntos familiares, aún no lo acabo de entender, pero prometo contestar y enviar el resultado final,
Gracias de nuevo