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
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"]." ";
echo "Text ".$_POST["txtFiltro"]." 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>
</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);
}
?>
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"]." ";
echo "Text ".$_POST["txtFiltro"]." 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>
</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.