?php
class Dselect
{
var $table_name;
var $sql;
var $sql_find_ziduan="id";
var $attribute_id;
//==============================
// 通过select_show函数传递过来的数据来构建查询语句
function creat_sql()
{
if(isset($_POST['select_table_name']))
{
$sql="select ".$this->sql_find_ziduan." from ".$_POST['select_table_name']." where " ;//两个通配符
$sql_add="";
for($i=1;$i<=9;$i++)
{
if(isset($_POST['select_list'.$i]))
{
switch ($_POST['select_type'.$i])
{
case 1://模糊
if($_POST['select'.$i]!="" )
{
$word=explode(" ",$_POST['select'.$i]);
$m=0;
while(isset($word[$m]))
{
$word[$m]=trim($word[$m]);
if(!empty($word[$m]))
$sql_add=$sql_add." and ".$_POST['select_list'.$i]." like '%".$word[$m]."%'";
$m++;
}
}
break;
case 2://菜单
if($_POST['select'.$i]!="" and $_POST['select'.$i]!=0)
{
$sql_add=" and ".$_POST['select_list'.$i]." =".$_POST['select'.$i];
}
break;
case 3://时间框(双框)
if($_POST['time_start'.$i]!="" and $_POST['time_end'.$i]!="")
{
$sql_add=' and '.$_POST['select_list'.$i].' between "'.$_POST['time_start'.$i].'" and "'.$_POST['time_end'.$i].'"';
}
elseif($_POST['time_start'.$i]!="" )
$sql_add=" and ".$_POST['select_list'.$i]." >= '".$_POST['time_start'.$i]."' ";
elseif($_POST['time_end'.$i]!="" )
$sql_add=" and ".$_POST['select_list'.$i]." <= '".$_POST['time_end'.$i]."' ";
break;
case 4://时间框(单框)
$sql_add=" and ".$_POST['select_list'.$i]." = '".$_POST['time_start'.$i]."'";
break;
case 5://时间框(已定义时间间隔)
$sql_add=" and ".$_POST['select_list'.$i]." = '".$_POST['time_start'.$i]."'";
break;
}
$sql=$sql.$sql_add;
$sql_add="";
}
}
$aa=explode("where",$sql);
if(strlen($aa[1])<=3)//判断where后跟的字符小于3个则认为SQL语句不完整需要构建不带where的sql语句
$sql=$aa[0];
else//去除where后跟随的and字符
{
$aa[1]=substr_replace($aa[1],"",1,4);
$sql=$aa[0]." where ".$aa[1]." order by id desc";
}
$this->sql=$sql;
//echo '
'.$sql;
}
// $this->add_tree_select($this->sql,$_POST['select_table_name']);
}
//=============================================================
//在SQL语句中增加目录树传递过来的信息
function add_tree_select($sql,$table_name)
{
if(isset($_GET['tree_id']))
{
if($sql=="")
{
$sql="select * from ".$table_name." where "."mulu".$_GET['level']."=".$_GET['tree_id'] ;//
}
else
{
$aa=array();
$aa=explode("where",$sql);
if(isset($aa[1]))
$sql=$aa[0]." where "."mulu".$_GET['level']."=".$_GET['tree_id']." and ".$aa[1];
else
$sql=$aa[0]." where "."mulu".$_GET['level']."=".$_GET['tree_id'];
}
}
$this->sql=$sql;
}
//============================
//选择框显示
function select_show($id)
{
echo '2222';
$sql="select * from table_select_attribute where id=".$id ;
$csql=query($sql) ;//设定$lnk
$rs=mysqli_fetch_array($csql);
if($_SESSION["post_id"]>=9000 )//是否有表头显示*********************************
{
echo '['.$id.']';
}
echo '