elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web (Moderador: #!drvy)
| | |-+  Ayuda "Búsqueda Ajax-Php-Mysql"
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ayuda "Búsqueda Ajax-Php-Mysql"  (Leído 1,256 veces)
edwarditos

Desconectado Desconectado

Mensajes: 9


Ver Perfil
Ayuda "Búsqueda Ajax-Php-Mysql"
« en: 14 Noviembre 2013, 22:01 pm »




Que tal amigos,
Tengo un script el cual busca en una tabla de una base de datos, el problema surge cuando quiero hacer una consulta de dos tablas distintas a la vez
Espero me pueda ayudar,

Les dejo el código:




Código
  1. bd: rokito
  2. //Esta tabla es la que busca el codigo que esta abajo
  3.  
  4. CREATE TABLE `laptop` (
  5.  `id_lap` INT(11) NOT NULL AUTO_INCREMENT,
  6.  `marcal` VARCHAR(12) NOT NULL,
  7.  `modelol` VARCHAR(15) NOT NULL,
  8.  `n_seriel` VARCHAR(20) NOT NULL,
  9.  `micro` VARCHAR(25) NOT NULL,
  10.  `disco_duro` VARCHAR(6) NOT NULL,
  11.  `memoria_Ram` VARCHAR(6) NOT NULL,
  12.  PRIMARY KEY (`id_lap`)
  13. ) ENGINE=InnoDB;
  14.  
  15.  
  16. ///Esta tabla es la que se requiere que tambien que busque junto con la anterior
  17.  
  18. CREATE TABLE `usuarios` (
  19. `iduser` INT(11) NOT NULL AUTO_INCREMENT,
  20. `nombre` VARCHAR(15) NOT NULL,
  21. `App` VARCHAR(15) NOT NULL,
  22. `Apm` VARCHAR(15) NOT NULL,
  23. `ciudad` VARCHAR(15) NOT NULL,
  24. `cod_post` VARCHAR(15) NOT NULL,
  25.  `id_lap` INT(11) NOT NULL,
  26. PRIMARY KEY (`iduser`),
  27. INDEX(id_lap),
  28. FOREIGN KEY(id_lap) REFERENCES laptop (id_lap)
  29. ON UPDATE RESTRICT
  30. ) ENGINE=InnoDB;


Código
  1. ____________________________________________________
  2. buscajax.php
  3.  
  4. <!DOCTYPE html>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  7. <html>
  8. <head><title>Buscador</title>
  9.  
  10. <script type="text/javascript" src="ajax.js"></script>
  11. <link rel="stylesheet" type="text/css" href="estilos.css" />
  12. </head>
  13.  
  14. <body>
  15. <center>
  16. <h1><b> LAPTOP´S </b></h1>
  17. </center>
  18. <center>
  19. BUSCAR <input type="text" id="bus" name="bus" onkeyup="loadXMLDoc()" required />
  20. <div id="myDiv"></div>
  21. </center>
  22. </body>
  23. </html>
  24.  


Código
  1. __________________________________________________________
  2. conexion.php
  3.  
  4. <?php
  5. function conexion(){
  6. $con = mysql_connect("localhost","root","");
  7. if (!$con){
  8. die('Could not connect: ' . mysql_error());
  9. }
  10. mysql_select_db("rokito", $con);
  11. return($con);
  12. }
  13. ?>
  14.  

Código
  1. __________________________________________________________
  2. proc.php
  3.  
  4. <?php include 'conexion.php';
  5.  
  6. $qwerty = $_POST['qwerty'];
  7. $con=conexion();
  8. $sql="SELECT * FROM laptop WHERE CONCAT (id_lap,' ',marcal,' ',modelol,' ',n_seriel,' ',micro,' ',disco_duro,' ',memoria_Ram ) LIKE '%".$qwerty."%'";
  9. $res=mysql_query($sql,$con);
  10. if(mysql_num_rows($res)==0){
  11. while($fila=mysql_fetch_array($res)){
  12.  
  13. }
  14.  
  15. echo '<b>No hay sugerencias</b>';
  16. }else{
  17. echo '<b>Sugerencias:</b><br />';
  18. echo '<b></b><br />';
  19.  
  20. echo "<table border='1'>
  21. <tr>
  22. <th>ID LAPTOP</th>
  23. <th>MARCA</th>
  24. <th>MODELO</th>
  25. <th>NUMERO DE SERIE</th>
  26. <th>MICROPROCESADOR</th>
  27. <th>DISCO DURO</th>
  28. <th>MEMORIA RAM</th>
  29. </tr>";
  30.  
  31. while($fila=mysql_fetch_array($res)){
  32.  
  33.  echo "<tr>";
  34.  echo "<td><a href='modificalap.php?id_lap".$fila['id_lap']."'>".$fila['id_lap']."</a></td> \n";
  35.  echo "<td>" . $fila['marcal'] . "</td>";
  36.  echo "<td>" . $fila['modelol'] . "</td>";
  37.  echo "<td>" . $fila['n_seriel'] . "</td>";
  38.  echo "<td>" . $fila['micro'] . "</td>";
  39.  echo "<td>" . $fila['disco_duro'] . "</td>";
  40.  echo "<td>" . $fila['memoria_Ram'] . "</td>";
  41.  echo "</tr>";
  42.  
  43. }
  44. }
  45. ?>

Código
  1. ________________________________________________
  2. ajax.js
  3.  
  4. function loadXMLDoc()
  5. {
  6. var xmlhttp;
  7. var n=document.getElementById('bus').value;
  8. if(n==''){
  9. document.getElementById("myDiv").innerHTML="";
  10. return;
  11. }
  12. if (window.XMLHttpRequest)
  13. {// code for IE7+, Firefox, Chrome, Opera, Safari
  14. xmlhttp=new XMLHttpRequest();
  15. }
  16. else
  17. {// code for IE6, IE5
  18. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  19. }
  20. xmlhttp.onreadystatechange=function()
  21. {
  22. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  23. {
  24. document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
  25. }
  26. }
  27. xmlhttp.open("POST","proc.php",true);
  28. xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  29. xmlhttp.send("qwerty="+n);
  30. }



Código
  1. _________________________________________________________
  2. estilos.css
  3.  
  4.  
  5. div
  6. {
  7.  
  8. margin-top: 10px;
  9. border-style:dashed;
  10. width: 1500px;
  11. height: 1500px;
  12. background-color:#F0FFF0;
  13. text-align: left;
  14. color:#00008B;
  15. padding:10px 10px;
  16. }
  17.  
  18. body{
  19. color:#696969;
  20. font-family:Arial,Helvetica,sans-serif;
  21. }


[/color]


« Última modificación: 21 Noviembre 2013, 00:28 am por edwarditos » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Ayuda] modificar "start page" en "internet explorer" con "batch"
Scripting
taton 7 16,623 Último mensaje 20 Septiembre 2006, 01:45 am
por taton
[BATCH] Ayuda con este script sobre "if exist" y "takeown" (SOLUCIONADO)
Scripting
SuperDraco 4 11,952 Último mensaje 30 Noviembre 2009, 21:05 pm
por Angel Doze
AYUDA: PHP no muestra tildes, "ñ" desde MySQL
PHP
NetStorm 2 5,322 Último mensaje 23 Febrero 2011, 01:50 am
por Nakp
Búsqueda múltiples Tablas con "dataTables"
Desarrollo Web
bavo08 1 1,558 Último mensaje 4 Diciembre 2014, 16:12 pm
por MinusFour
php mysql ajax en mvc
PHP
Yorshdelaselva 4 4,124 Último mensaje 9 Agosto 2016, 22:09 pm
por Adrialmend
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines