Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Pasar cadena SQL por parametros en la URL

Estas en el tema de Pasar cadena SQL por parametros en la URL en el foro de Frameworks JS en Foros del Web. Buenas a todos, estoy utilizando AJAX para mostrar 2 paginas en una mediante la funcion "include", aqui les dejo los codigos de las paginas: Listar.php ...
  #1 (permalink)  
Antiguo 11/03/2010, 14:30
 
Fecha de Ingreso: diciembre-2008
Mensajes: 1
Antigüedad: 17 años, 6 meses
Puntos: 0
Exclamación Pasar cadena SQL por parametros en la URL

Buenas a todos, estoy utilizando AJAX para mostrar 2 paginas en una mediante la funcion "include", aqui les dejo los codigos de las paginas:

Listar.php
Código PHP:
<div id="BuscarCiudadanos"><?php include('buscarciudadanos.php'); ?></div>
<div id="EdicionCiudadanos"><?php include('mostrartablaciudadanos.php');?></div>
buscarciudadanos.php

Código HTML:
<script language="javascript" type="text/javascript">

function MakeWhereQuery()
{
	var SQL = "VACIA";
	if(document.getElementById("chkNombre").checked || document.getElementById("chkApellidoP").checked || document.getElementById("chkApellidoM").checked || document.getElementById("chkCiudad").checked || document.getElementById("chkComunidad").checked || document.getElementById("chkCalle").checked || document.getElementById("chkNumero").checked || document.getElementById("chkTelefono").checked || document.getElementById("chkCelular").checked || document.getElementById("chkCorreo").checked)
	{	
		var hayAND = false;
		SQL = "WHERE ";
		if (document.getElementById("chkNombre").checked)
		{
			SQL = SQL + " Nombre = '%" + document.getElementById("txtNombre").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkApellidoP").checked)
		{
			if (hayAND)
				SQL = SQL + " AND ApellidoPaterno = '%" + document.getElementById("txtApellidoP").value + "%'";
			else
				SQL = SQL + " ApellidoPaterno = '%" + document.getElementById("txtApellidoP").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkApellidoM").checked)
		{
			if (hayAND)
				SQL = SQL + " AND ApellidoMaterno = '%" + document.getElementById("txtApellidoM").value + "%'";
			else
				SQL = SQL + " ApellidoMaterno = '%" + document.getElementById("txtApellidoM").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkCiudad").checked)
		{
			if (hayAND)
				SQL = SQL + " AND id_municipio = " + document.getElementById("ddlCiudad").value;
			else
				SQL = SQL + " id_municipio = " + document.getElementById("ddlCiudad").value;
			hayAND = true;
		}
		if (document.getElementById("chkComunidad").checked)
		{
			if (hayAND)
				SQL = SQL + " AND id_comunidad = " + document.getElementById("ddlComunidad").value;
			else
				SQL = SQL + " id_comunidad = " + document.getElementById("ddlComunidad").value;
			hayAND = true;
		}
		if (document.getElementById("chkCalle").checked)
		{
			if (hayAND)
				SQL = SQL + " AND calle = '%" + document.getElementById("txtCalle").value + "%'";
			else
				SQL = SQL + " calle = '%" + document.getElementById("txtCalle").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkNumero").checked)
		{
			if (hayAND)
				SQL = SQL + " AND numero = '%" + document.getElementById("txtNumero").value + "%'";
			else
				SQL = SQL + " numero = '%" + document.getElementById("txtNumero").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkTelefono").checked)
		{
			if (hayAND)
				SQL = SQL + " AND telefono = '%" + document.getElementById("txtTelefono").value + "%'";
			else
				SQL = SQL + " telefono = '%" + document.getElementById("txtTelefono").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkCelular").checked)
		{
			if (hayAND)
				SQL = SQL + " AND celular = '%" + document.getElementById("txtCelular").value + "%'";
			else
				SQL = SQL + " celular = '%" + document.getElementById("txtCelular").value + "%'";
			hayAND = true;
		}
		if (document.getElementById("chkCorreo").checked)
		{
			if (hayAND)
				SQL = SQL + " AND correo = '%" + document.getElementById("txtCorreo").value + "%'";
			else
				SQL = SQL + " correo = '%" + document.getElementById("txtCorreo").value + "%'";
			hayAND = true;
		}		
		cargaPagina('EdicionCiudadanos','includes/ciudadanos/mostrartablaciudadanos.php?RedeclararClase=si&IsWhere=' + SQL);
	}
}

</script>

<input type="checkbox" id="chkNombre" onclick="document.getElementById('ShowHideNombre').style.display = (this.checked) ? 'block' : 'none' " />
<strong>Nombre:</strong><br />
<div id="ShowHideNombre" style="display:none">
	<input id="txtNombre" name="txtNombre" type="text" size="20" /><br />
</div>

<!-- AQUI ESTAN LOS DEMAS CAMPOS PERO COMO HAY TEXTO LIMITADO PARA MOSTRAR EN EL FORO LOS QUITE, HAGANLOS OBVIOS -->

<input type="checkbox" id="chkCorreo" onclick="document.getElementById('ShowHideCorreo').style.display = (this.checked) ? 'block' : 'none' " />
<strong>Correo Electrónico:</strong><br />
<div id="ShowHideCorreo" style="display:none">
	<input id="txtCorreo" name="txtCorreo" type="text" size="40" /><br />
</div>

<input type="button" id="Buscar" value="Buscar" onclick="MakeWhereQuery();" /> 


mostrartablaciudadanos.php
Código PHP:
<script language="javascript">
function asking(id, nombre)

    var answer = confirm ("¿Está seguro de eliminar el registro del ciudadano " + nombre + "?")

    if (answer)
        cargaPagina("EdicionCiudadanos","includes/ciudadanos/eliminar.php?id_ciudadano=" + id);
}

</script>



<?php 

if(!empty($_GET['RedeclararClase']))
{
    include(
'../../conn/MySQL.php');
}

$sql "SELECT C.id_ciudadano, C.Nombre, C.ApellidoPaterno, C.ApellidoMaterno, C.id_municipio, M.nombre_municipio, C.id_comunidad, CM.nombre_comunidad, C.calle, C.numero, C.telefono, C.correo, C.celular, C.fecha_registro FROM (ciudadanos AS C INNER JOIN municipios AS M ON C.id_municipio = M.id_municipio) INNER JOIN comunidad AS CM ON C.id_comunidad = CM.id_comunidad ";

if(!empty(
$_GET[['IsWhere']))
{
    
$sql $sql $_GET[['IsWhere'];
}

$db = &new MySQL();

$result $db->query($sql);

//Mostrar tabla
echo '<table border="1">';
echo 
'    <tr>';
echo 
'        <td>';
echo 
'            ';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Nombre(s)</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Apellido Paterno</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Apellido Materno</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Municipio</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Colonia/Comunidad</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Calle</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>N&uacute;mero</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Tel&eacute;fono</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Celular</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Correo Electr&oacute;nico</strong>';
echo 
'        </td>';
echo 
'        <td>';
echo 
'            <strong>Fecha de Registro</strong>';
echo 
'        </td>';
echo 
'    </tr>';
while(
$row $result->fetch())
{
    echo 
'    <tr>';
    echo 
'        <td>';
    echo 
'            <a style="text-decoration:underline; cursor:pointer;" onclick="cargaPagina(\'EdicionCiudadanos\',\'includes/ciudadanos/modificardatos.php?id_ciudadano='.$row['id_ciudadano'].'&nombre='.$row['nombre'].'&nombre='.$row['Nombre'].'&ApellidoPaterno='.$row['ApellidoPaterno'].'&ApellidoMaterno='.$row['ApellidoMaterno'].'&id_municipio='.$row['id_municipio'].'&nombre_municipio='.$row['nombre_municipio'].'&=id_comunidad'.$row['id_comunidad'].'&nombre_comunidad='.$row['nombre_comunidad'].'&calle='.$row['calle'].'&numero='.$row['numero'].'&telefono='.$row['telefono'].'&celular='.$row['celular'].'&correo='.$row['correo'].'&=fecha_registro='.$row['fecha_registro'].'\')">Editar</a>';
    echo 
'            <a style="text-decoration:underline; cursor:pointer;" onclick="javascript:asking(\''.$row['id_ciudadano'].'\',\''.$row['Nombre'].' '.$row['ApellidoPaterno'].' '.$row['ApellidoMaterno'].'\')">Eliminar</a>';
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['Nombre'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['ApellidoPaterno'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['ApellidoMaterno'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['nombre_municipio'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['nombre_comunidad'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['calle'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['numero'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['telefono'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['celular'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['correo'];
    echo 
'        </td>';
    echo 
'        <td>';
    echo 
'            '.$row['fecha_registro'];
    echo 
'        </td>';
    echo 
'    </tr>';
}

echo 
'</table>';
echo 
'<br>';
?>
Como pueden ver en la parte de $sql = $sql + $_GET[['IsWhere']; quiere concatenar la cadena SQL con la parte del WHERE pero me aparece como vacia, no se si tenga algo que ver con los signos de "=" dentro del where.

¿Por que me aparece vacio el parametro IsWhere o que estoy haciendo mal?

Etiquetas: ajax, parametros
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:44.