Foros del Web » Programando para Internet » PHP »

PHP OO buscar, insertar y leer archivos xml en php

Estas en el tema de buscar, insertar y leer archivos xml en php en el foro de PHP en Foros del Web. hola soy nuevo aqui pero necesito un poco de ayuda lo que quiero hacer es crear un buscador en php pero que la busqueda lo ...
  #1 (permalink)  
Antiguo 18/05/2012, 11:10
 
Fecha de Ingreso: mayo-2012
Mensajes: 1
Antigüedad: 11 años, 10 meses
Puntos: 0
Información buscar, insertar y leer archivos xml en php

hola soy nuevo aqui pero necesito un poco de ayuda lo que quiero hacer es crear un buscador en php pero que la busqueda lo haga de unn archivo xml y despues al darle click al nombre que estoy buscando me mande a una pagina con todos los datos del xml del nombre que le estoy dando click muestro el codigo que llevo de ante mano muchas gracias y espero una respuesta

XML:
<root>
<element>
<ruta>AN3101</ruta>
<matricula>61023</matricula>
<nombre_medico>BONIFACIO AGUILAR GRIMALDO</nombre_medico>
<direccion>JOSE BENITEZ 2704</direccion>
<localidad>OBISPADO</localidad>
<cp>64060</cp>
<ciudad>MONTERREY</ciudad>
<municipio>MONTERREY</municipio>
<estado>NUEVO LEÓN</estado>
<especialidad>MEDICINA INTERNA</especialidad>
</element>
<element>
<ruta>AN3101</ruta>
<matricula>104213</matricula>
<nombre_medico>RAUL CUELLAR MORENO</nombre_medico>
<direccion>MATAMOROS 561 PONIENTE</direccion>
<localidad>TORREÓN CENTRO</localidad>
<cp>27000</cp>
<ciudad>TORREÓN</ciudad>
<municipio>TORREÓN</municipio>
<estado>COAHUILA DE ZARAGOZA</estado>
<especialidad>NEUROCIRUGIA</especialidad>
</element>
<element>
<ruta>AN3101</ruta>
<matricula>725245</matricula>
<nombre_medico>ABELARDO LEAL GONZALEZ</nombre_medico>
<direccion>FRANCISCO GARZA SADA</direccion>
<localidad>CHEPEVERA</localidad>
<cp>64030</cp>
<ciudad>MONTERREY</ciudad>
<municipio>MONTERREY</municipio>
<estado>NUEVO LEÓN</estado>
<especialidad>GERIATRÍA</especialidad>
</element>
<element>
<ruta>AN3101</ruta>
<matricula>678877</matricula>
<nombre_medico>VICTOR MANUEL LEOS MARTINEZ</nombre_medico>
<direccion>HIDALGO 2425</direccion>
<localidad>OBISPADO</localidad>
<cp>64060</cp>
<ciudad>MONTERREY</ciudad>
<municipio>MONTERREY</municipio>
<estado>NUEVO LEÓN</estado>
<especialidad>NEUROCIRUGIA</especialidad>
</element>
<element>
<ruta>AN3101</ruta>
<matricula>452411</matricula>
<nombre_medico>JOSE LUIS MENDIZABAL MONTES</nombre_medico>
<direccion>MORELOS 700 OTE</direccion>
<localidad>TORREÓN CENTRO</localidad>
<cp>27000</cp>
<ciudad>TORREÓN</ciudad>
<municipio>TORREÓN</municipio>
<estado>COAHUILA DE ZARAGOZA</estado>
<especialidad>NEUROLOGIA</especialidad>
</element>
<element>
<ruta>AN3101</ruta>
<matricula>61623</matricula>
<nombre_medico>JESUS MURAIRA GONZALEZ</nombre_medico>
<direccion>HIDALGO 2425</direccion>
<localidad>OBISPADO</localidad>
<cp>64060</cp>
<ciudad>MONTERREY</ciudad>
<municipio>MONTERREY</municipio>
<estado>NUEVO LEÓN</estado>
<especialidad>NEUROCIRUGIA</especialidad>
</element>
</root>

html index

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>

<!-- Basic Page Needs
================================================== -->
<meta charset="utf-8">
<title>Sigev</title>
<meta name="description" content="">
<meta name="author" content="">

<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

<!-- CSS
================================================== -->
<link rel="stylesheet" href="stylesheets/base.css">
<link rel="stylesheet" href="stylesheets/skeleton.css">
<link rel="stylesheet" href="stylesheets/layout.css">

<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- Favicons
================================================== -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>

</head>
<body>

<!-- Primary Page Layout
================================================== -->

<!-- Delete everything in this .container and get started on your own site! -->

<div class="container">
<div class="sixteen columns">
<h1 class="remove-bottom" style="margin-top: 40px">Sigev</h1><br/>
</div>
<div class="one-third column">
<form>
<p><strong>Buscar:</strong></p><input type="text" size="30" onkeyup="showResult(this.value)" />
<script>
$(document).ready(function(){
$("#busqueda_avanzada").click(function(evento){
if ($("#busqueda_avanzada").attr("checked"))
{
$("#formularioavanzado").css("display", "block");
}
else
{
$("#formularioavanzado").css("display", "none");
}
});
});
</script>
<input type="checkbox" name="avanzada" value="1" id="busqueda_avanzada"> Busqueda Avanzada
<br/><br/>
<div id="formularioavanzado" style="display: none;">
<form action="#" method="post">
Nombre: <input type="text" name="nombre">
Apellido: <input type="text" name="apellido">
Especialidad: <input type="text" name="especialidad">
Dirección: <input type="text" name="direccion">
CP: <input type="text" name="cp">
Delegacion/Municipio: <input type="text" name="delmun">
Estado: <input type="text" name="edo">
Email: <input type="text" name="email">
<input type="submit" value="Buscar">
</form>
</div>
</div>
<div class="one-third column">
<div id="livesearch"></div>
</form>
</div>

</div><!-- container -->



<!-- JS
================================================== -->
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="javascripts/tabs.js"></script>
<script type="text/javascript">
function showResult(str)
{
if (str.length==0)
{
document.getElementById("livesearch").innerHTML="" ;
document.getElementById("livesearch").style.border ="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{//code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("livesearch").innerHTML=xm lhttp.responseText;
document.getElementById("livesearch").style.border ="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","buscar.php?q="+str,true);
xmlhttp.send();
}
</script>

<!-- End Document
================================================== -->
</body>
</html>

php buscar.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link href="GreyBox_v5_54/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
<script type="text/javascript">
var GB_ROOT_DIR = "./Greybox_v5_54/greybox/";
</script>

<script type="text/javascript" src="GreyBox_v5_54/greybox/AJS.js"></script>
<script type="text/javascript" src="GreyBox_v5_54/greybox/gb_scripts.js"></script>
</head>
<body>
<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("teva.xml");

$x=$xmlDoc->getElementsByTagName('element');

//get the q parameter from URL
$q=$_GET["q"];

//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('nombre_medico');
$z=$x->item($i)->getElementsByTagName('ruta');
if ($y->item(0)->nodeType==1)
{
//find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
".php' rel='gb_pageset[search_sites]'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "<br /><a href='" .
$z->item(0)->childNodes->item(0)->nodeValue .
".php' rel='gb_pageset[search_sites]'>" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
{
$response="<a href='http://www.yahoo.com.mx' rel='gb_pageset[search_sites]'>no hay sugerencias</a>";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>
</body>
</html>


y otra cosa no funciona mi pop up que puse a lo mejor por el buscar.php no esta en index fisicamente ojala y le puedan echar un oja y me puedan ayudar

Etiquetas: ajax, xml, buscadores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:21.