Saludos, tengo una consulta he echo una busqueda con combo box, pero me aparecen todos los registros y no por lo que yo yo he seleccionado desde los combo(en este caso de peru, colombia lo tengo vacio)
se los agradeceria si me ayuden a ver el error y como solucionarlo:
<?php include "conexion.php";?>
<html>
<head>
<title>Anuncios gratis, videos</title>
<link rel="stylesheet" href="estilo-general.css" type="text/css" media="all">
</head>
<script>
//hacer que funcione con diferentes navegadores
function requerir(){
try{
req=new XMLHttpRequest();
}catch(err1){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err3){
req= false;
}
}
}
return req;
}
var peticion=requerir();
function llamarAjaxGETpro(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("departamento").value;
var url="provincia.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxpro;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}
function llamarAjaxGETdis(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("provincia").value;
var url="distrito.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxdis;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}
function respuestaAjaxpro(){
if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("pro").innerHTML=peticion.responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
function respuestaAjaxdis(){
if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("dis").innerHTML=peticion.responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
</script>
<body>
<div id="global">
<div id="busqueda">
<form name="form1" method="post" enctype="application/x-www-form-urlencoded"action="busquedapropiedade6.php" >
<div id="dep" style="width:150px; float:left">
<label>Que Buscas:
<input type="text" name="txtBusqueda" id="txtBusqueda">
<select name="departamento" id="departamento" onchange="llamarAjaxGETpro()">
<option>seleccione pais.</option>
<?php
$re=mysql_query("select * from paises");
while($f=mysql_fetch_array($re)){
echo'<option value="'.$f['id_pais'].'">'.$f['pais'].'</option>';
}
?>
</select>
</div>
<div id="pro" style="width:150px; float:left">
<select name="pro" id="pro" >
<option value="" selected></option>
<option value="<?php echo $registrociudad['id']; ?>"><?php echo $registrociudad['nombre']; ?></option>
</select>
</div>
<input type="submit" name="cmdBuscar" id="cmdBuscar" value="IR">
</form>
<?php
$sql = "SELECT usuarios.*, ciudades.* FROM usuarios, ciudades WHERE usuarios.segundo = ciudades.id";
if (isset($_POST['txtBusqueda'])) {
$sql .= " AND usuarios.titulo LIKE '%" . $_POST['txtBusqueda'] . "%' ";
if (intval($_POST['pro']) > 0) {
$sql .= " AND usuarios.segundo = '" . intval($_POST['pro']) . "'";
}
}
$sql .= " ORDER BY ciudades.nombre ASC";
$re=mysql_query($sql);
while($f=mysql_fetch_array($re)){
?>
<div id="tabla">
<TABLE WIDTH="95%" CELLPADDING="2" CELLSPACING="0" BORDER="1">
<TR>
<TD ROWSPAN="3" WIDTH="20%"><?php echo '<img src="'.$f['foto'].'" onmouseover="this.width=150;this.height=75;" onmouseout="this.width=100;this.height=50;" width="100" height="50" alt="" />
/>';?></TD>
<TD WIDTH="53%" ><?php echo $f['titulo'].'<br>';?></TD>
<TD WIDTH="33%"ALIGN="left"><?php echo $f['precio'].'<br>';?></TD>
</TR>
<TR>
<TD WIDTH="73%" ALIGN="left"><?php echo $f['contenido'].'<br>';?></TD>
<TD WIDTH="10%"><?php echo $f['id_ciudad'].'<br>';?><?php echo $f['nombre']; ?></TD>
</TR>
</TABLE>
</div>
<?php
}
mysql_free_result($re);
mysql_close($conexion);
?>
</div>
</div>
se los agradeceria si me ayuden a ver el error y como solucionarlo:
<?php include "conexion.php";?>
<html>
<head>
<title>Anuncios gratis, videos</title>
<link rel="stylesheet" href="estilo-general.css" type="text/css" media="all">
</head>
<script>
//hacer que funcione con diferentes navegadores
function requerir(){
try{
req=new XMLHttpRequest();
}catch(err1){
try{
req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(err2){
try{
req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err3){
req= false;
}
}
}
return req;
}
var peticion=requerir();
function llamarAjaxGETpro(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("departamento").value;
var url="provincia.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxpro;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}
function llamarAjaxGETdis(){
var aleatorio=parseInt(Math.random()*999999999);
valor=document.getElementById("provincia").value;
var url="distrito.php?valor="+valor+"&r="+aleatorio;
peticion.open("GET",url,true);
peticion.onreadystatechange =respuestaAjaxdis;
peticion.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
peticion.send(null);
}
function respuestaAjaxpro(){
if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("pro").innerHTML=peticion.responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
function respuestaAjaxdis(){
if(peticion.readyState==4){
if(peticion.status==200){
//alert(peticion.responseText);
document.getElementById("dis").innerHTML=peticion.responseText;
}else{
alert("ha ocurrido un error"+peticion.statusText);
}
}
}
</script>
<body>
<div id="global">
<div id="busqueda">
<form name="form1" method="post" enctype="application/x-www-form-urlencoded"action="busquedapropiedade6.php" >
<div id="dep" style="width:150px; float:left">
<label>Que Buscas:
<input type="text" name="txtBusqueda" id="txtBusqueda">
<select name="departamento" id="departamento" onchange="llamarAjaxGETpro()">
<option>seleccione pais.</option>
<?php
$re=mysql_query("select * from paises");
while($f=mysql_fetch_array($re)){
echo'<option value="'.$f['id_pais'].'">'.$f['pais'].'</option>';
}
?>
</select>
</div>
<div id="pro" style="width:150px; float:left">
<select name="pro" id="pro" >
<option value="" selected></option>
<option value="<?php echo $registrociudad['id']; ?>"><?php echo $registrociudad['nombre']; ?></option>
</select>
</div>
<input type="submit" name="cmdBuscar" id="cmdBuscar" value="IR">
</form>
<?php
$sql = "SELECT usuarios.*, ciudades.* FROM usuarios, ciudades WHERE usuarios.segundo = ciudades.id";
if (isset($_POST['txtBusqueda'])) {
$sql .= " AND usuarios.titulo LIKE '%" . $_POST['txtBusqueda'] . "%' ";
if (intval($_POST['pro']) > 0) {
$sql .= " AND usuarios.segundo = '" . intval($_POST['pro']) . "'";
}
}
$sql .= " ORDER BY ciudades.nombre ASC";
$re=mysql_query($sql);
while($f=mysql_fetch_array($re)){
?>
<div id="tabla">
<TABLE WIDTH="95%" CELLPADDING="2" CELLSPACING="0" BORDER="1">
<TR>
<TD ROWSPAN="3" WIDTH="20%"><?php echo '<img src="'.$f['foto'].'" onmouseover="this.width=150;this.height=75;" onmouseout="this.width=100;this.height=50;" width="100" height="50" alt="" />
/>';?></TD>
<TD WIDTH="53%" ><?php echo $f['titulo'].'<br>';?></TD>
<TD WIDTH="33%"ALIGN="left"><?php echo $f['precio'].'<br>';?></TD>
</TR>
<TR>
<TD WIDTH="73%" ALIGN="left"><?php echo $f['contenido'].'<br>';?></TD>
<TD WIDTH="10%"><?php echo $f['id_ciudad'].'<br>';?><?php echo $f['nombre']; ?></TD>
</TR>
</TABLE>
</div>
<?php
}
mysql_free_result($re);
mysql_close($conexion);
?>
</div>
</div>