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
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  CONSULTA DE TABLAS POR FILTRADO DE TEXTO
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: CONSULTA DE TABLAS POR FILTRADO DE TEXTO  (Leído 3,583 veces)
smagno

Desconectado Desconectado

Mensajes: 22


Ver Perfil
CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« en: 26 Octubre 2009, 15:18 pm »

Estoy realizando una consulta generalizada por tablas.

Bueno cuando entro por primera vez funciona haciendo la consulta, pero cuando presiono el boton buscar para hacer el filtrado. se pierden los datos iniciales lo mismo que las sessiones y me muestra el siguiente mensaje

Código:
SELECT , FROM ORDER BY
MySql Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' FROM ORDER BY' at line 1

disculpen el poco de echo ya que asi pude mirar el error.

Que estoy haciendo mal???
Aqui esta el codigo..

Código:
<?php
session_start();

$cTabla  = trim($_GET['cTabla']);
$cCampo1 = trim($_GET['cCampo1']);
$cCampo2 = trim($_GET['cCampo2']);
$cOrden  = trim($_GET['cOrden']);
$nCondi  = trim($_GET['nCondi']);
$cCondi  = trim($_GET['cCondi']);

$_SESSION['s_cTabla'] = $cTabla;

echo 'Tabla: '.$cTabla.' Tabla session :'.$_SESSION['s_cTabla'];

if($cOrden=='N'){
$cOrden=$cCampo2;}
else{
$cOrden=$cCampo1;}

$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";

if (isset ($Buscar)) { //Si fue apretado el botón buscar

echo "Select ".$_POST["selFiltro"]."&nbsp;";
echo "Text   ".$_POST["txtFiltro"]."&nbsp; tabla session:".$_SESSION['s_cTabla'];

$SelFiltro = trim($_POST['selFiltro']);
$txtFiltro = trim($_POST['txtFiltro']);

if ($SelFiltro == "N"){
$cOrder = $cCampo2;
}else{
$cOrder = $cCampo1;
}
if ($txtFiltro==NULL){
if($SelFiltro == "N"){
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";
echo "pase por aqui";
}else{
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo1";
}
}else{
if($SelFiltro == "N"){
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";
}else{
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo1";
}
}
echo "paso 2".$sql;

MostrarConsulta();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>

<title>.:: MAGNO ::. Buscar Datos</title>
    <link rel="shortcut icon" href="../img/magno.ico" type="image/x-icon" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <link href="../css/HeaderFr.css" rel="stylesheet" type="text/css" />


    <script>

        function efecto(id,tip)
        {
          var col = '#3399FF'
          if(tip==2){col=""}
          var cel = document.getElementById(id)
          cel.style.backgroundColor=col
        }
        function llama(php)
        {
          document.location.href=php
        }

</script>
    
</head>
<body>
<form action="<?=$PHP_SELF?>" method="post" >
     <div>
<table>
<tr>
         <td style="width: 100px">
                     <table>
<tr>
                             <td style="width: 82px; height: 22px">
<select name="selFiltro">
           <option value="N" selected> Nombre</option>
           <option value="C"> Codigo</option>
         </select>
                                </td>
                                <td style="width: 82px">
<input name="txtFiltro" type="text" font-names="Verdana" size="46px">
                                </td>
                                <td style="width: 82px"><input type="submit" name="Buscar" value="Buscar" onClick=""></td>
                            </tr>
<tr>
                             <td colspan="3" style="width: 50px" valign="top">
                               <div id="divGrid" class="Marco" style="overflow: auto; width: 456px; height: 400px">

<?
MostrarConsulta()
                                        ?>
                                 </div>
</td>
                           </tr>
                       </table>
                        &nbsp;
                    </td>
               </tr>
           </table>
       </div>
   </form>
</body>
</html>
<?
function MostrarConsulta(){

include_once("clases/funciones.class.php");

global $cTabla, $cCampo1, $cCampo2, $cOrden, $nCondi, $cCondi, $sql;

   $fun = new Funciones();
    $fun->conecta();

$ali = array("left","left"); //alineacion
    $wid = array(90,290); //width
    $ico = array( array("edit.png","Click para Seleccionar o Editar",""), array("delete.png","Click para Eliminar",""));
echo "paso 1".$sql;
    $res = $fun->consulta($sql);
    $fun->lista($res,$ali,$wid,$ico);

}
?>

Gracias de antemano.


En línea

DarkItachi


Desconectado Desconectado

Mensajes: 516


Itachi Uchiha


Ver Perfil
Re: CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« Respuesta #1 en: 26 Octubre 2009, 18:00 pm »

Estoy realizando una consulta generalizada por tablas.

Bueno cuando entro por primera vez funciona haciendo la consulta, pero cuando presiono el boton buscar para hacer el filtrado. se pierden los datos iniciales lo mismo que las sessiones y me muestra el siguiente mensaje

Código:
SELECT , FROM ORDER BY
MySql Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' FROM ORDER BY' at line 1

disculpen el poco de echo ya que asi pude mirar el error.

Que estoy haciendo mal???
Aqui esta el codigo..

Código:
<?php
session_start();

$cTabla  = trim($_GET['cTabla']);
$cCampo1 = trim($_GET['cCampo1']);
$cCampo2 = trim($_GET['cCampo2']);
$cOrden  = trim($_GET['cOrden']);
$nCondi  = trim($_GET['nCondi']);
$cCondi  = trim($_GET['cCondi']);

$_SESSION['s_cTabla'] = $cTabla;

echo 'Tabla: '.$cTabla.' Tabla session :'.$_SESSION['s_cTabla'];

if($cOrden=='N'){
$cOrden=$cCampo2;}
else{
$cOrden=$cCampo1;}

$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";

if (isset ($Buscar)) { //Si fue apretado el botón buscar

echo "Select ".$_POST["selFiltro"]."&nbsp;";
echo "Text   ".$_POST["txtFiltro"]."&nbsp; tabla session:".$_SESSION['s_cTabla'];

$SelFiltro = trim($_POST['selFiltro']);
$txtFiltro = trim($_POST['txtFiltro']);

if ($SelFiltro == "N"){
$cOrder = $cCampo2;
}else{
$cOrder = $cCampo1;
}
if ($txtFiltro==NULL){
if($SelFiltro == "N"){
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";
echo "pase por aqui";
}else{
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo1";
}
}else{
if($SelFiltro == "N"){
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo2";
}else{
$sql = "SELECT $cCampo1, $cCampo2 FROM $cTabla ORDER BY $cCampo1";
}
}
echo "paso 2".$sql;

MostrarConsulta();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<head>

<title>.:: MAGNO ::. Buscar Datos</title>
    <link rel="shortcut icon" href="../img/magno.ico" type="image/x-icon" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <link href="../css/HeaderFr.css" rel="stylesheet" type="text/css" />


    <script>

        function efecto(id,tip)
        {
          var col = '#3399FF'
          if(tip==2){col=""}
          var cel = document.getElementById(id)
          cel.style.backgroundColor=col
        }
        function llama(php)
        {
          document.location.href=php
        }

</script>
    
</head>
<body>
<form action="<?=$PHP_SELF?>" method="post" >
     <div>
<table>
<tr>
         <td style="width: 100px">
                     <table>
<tr>
                             <td style="width: 82px; height: 22px">
<select name="selFiltro">
           <option value="N" selected> Nombre</option>
           <option value="C"> Codigo</option>
         </select>
                                </td>
                                <td style="width: 82px">
<input name="txtFiltro" type="text" font-names="Verdana" size="46px">
                                </td>
                                <td style="width: 82px"><input type="submit" name="Buscar" value="Buscar" onClick=""></td>
                            </tr>
<tr>
                             <td colspan="3" style="width: 50px" valign="top">
                               <div id="divGrid" class="Marco" style="overflow: auto; width: 456px; height: 400px">

<?
MostrarConsulta()
                                        ?>
                                 </div>
</td>
                           </tr>
                       </table>
                        &nbsp;
                    </td>
               </tr>
           </table>
       </div>
   </form>
</body>
</html>
<?
function MostrarConsulta(){

include_once("clases/funciones.class.php");

global $cTabla, $cCampo1, $cCampo2, $cOrden, $nCondi, $cCondi, $sql;

   $fun = new Funciones();
    $fun->conecta();

$ali = array("left","left"); //alineacion
    $wid = array(90,290); //width
    $ico = array( array("edit.png","Click para Seleccionar o Editar",""), array("delete.png","Click para Eliminar",""));
echo "paso 1".$sql;
    $res = $fun->consulta($sql);
    $fun->lista($res,$ali,$wid,$ico);

}
?>

Gracias de antemano.

Para mí que no recibes bien las variables.
Código
  1. $cTabla  = trim($_GET['cTabla']);
  2. $cCampo1 = trim($_GET['cCampo1']);
  3. $cCampo2 = trim($_GET['cCampo2']);
  4. $cOrden  = trim($_GET['cOrden']);
  5. $nCondi  = trim($_GET['nCondi']);
  6. $cCondi  = trim($_GET['cCondi']);
  7.  
  8. $_SESSION['s_cTabla'] = $cTabla;

Si las variables estuviesen vacías el resultado sería el que da el error.


En línea

Come to me when you have these eyes...

By more that you try it, a feather never will achieve to fly.
smagno

Desconectado Desconectado

Mensajes: 22


Ver Perfil
Re: CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« Respuesta #2 en: 26 Octubre 2009, 18:09 pm »

DarkItachi,

Si las recibo bien por que el inicialmente el me hace la consulta bien pero cuando voy hacer un filtrado y presiono buscar se pierde el contenido de las variables.
« Última modificación: 27 Octubre 2009, 01:18 am por smagno » En línea

DarkItachi


Desconectado Desconectado

Mensajes: 516


Itachi Uchiha


Ver Perfil
Re: CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« Respuesta #3 en: 26 Octubre 2009, 23:41 pm »

KarkItachi

Arghhh eso dolió....

inicial mente
Aghh eso dolió aún más!  :o

Prueba sin la función trim() a ver. ;)
En línea

Come to me when you have these eyes...

By more that you try it, a feather never will achieve to fly.
Mr. Crowley


Desconectado Desconectado

Mensajes: 343


Costa Rica


Ver Perfil WWW
Re: CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« Respuesta #4 en: 26 Octubre 2009, 23:49 pm »

Hola, no he leido mucho el codigo... pero OJO aqui:

function MostrarConsulta()

Por lo que veo es una funcion PHP...

Código:
<div id="divGrid" class="Marco" style="overflow: auto; width: 456px; height: 400px">
<?
MostrarConsulta()
?>
</div>

Esta confundiendo javascript con PHP... la funcion que llama en esa capa debe ser la
de javascript... poque seria Ajax quien hace la consulta y luego trae el resultado a la
capa divGrid.

Como le digo, no he leido el codigo... pero el error debe de estar ahi  :rolleyes:
En línea

Mi blog personal: www.calirojas.com
smagno

Desconectado Desconectado

Mensajes: 22


Ver Perfil
Re: CONSULTA DE TABLAS POR FILTRADO DE TEXTO
« Respuesta #5 en: 27 Octubre 2009, 01:36 am »

Mr. Crowley

MostrarConsulta() si es una funcion php inicialmente si me realiza la consulta pero cuando presiono el boton buscar en el post se pierde todo el contenido de las variables lo mismo que las variables de session [$cTabla, $cCampo1, $cCampo2, $cOrden, $nCondi, $cCondi] quedan en blanco.

Aprovecho y te comento ya realizo el popup de la ventana para hacer la busqueda de la consulta perfectamente.

Ahora se me presenta este problema no encuentro forma para solucionarlo.

!!! AMIGO CROWLEY NO SE ME PIERDA YA QUE UD. A SIDO UNA AYUDA MUY IMPORTANTE !!!

Agradeciendole de antemano.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
consulta para muestra con 2 tablas
Bases de Datos
maxmag 0 2,285 Último mensaje 4 Julio 2012, 05:43 am
por maxmag
consulta msql en tablas con campos ID
Dudas Generales
yosoytusol 5 3,075 Último mensaje 30 Agosto 2014, 10:04 am
por Markul
Consulta de multiples tablas de mysql
Bases de Datos
soy_nicanor 4 4,437 Último mensaje 17 Mayo 2015, 06:28 am
por ZeroVzla
Filtrado de texto en Linux
GNU/Linux
MasterAndHack 1 1,548 Último mensaje 6 Enero 2016, 16:26 pm
por MasterAndHack
consulta a estas tablas en mysql
Desarrollo Web
elmatador2 1 1,824 Último mensaje 14 Julio 2016, 16:02 pm
por soyloqbuskas
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines