Ask questions about modifying the date search

Source: Internet
Author: User
Ask questions about modifying the date search
???????????????????????????????????????? ????????????
I am using the Empire CMS
The respective search templates are set in \ web \ e \ search \ index. php, which corresponds to the column ID, $ s_tempid = (int) $ _ POST ['classid'];
If you select column 1, you can search by year or month;
If column 2 is selected, it can only be queried in the same year and in the same month. Otherwise, an error occurs,
Select column 3 and column 2 for the same purpose. you can only query in the same year and month; otherwise, an error is displayed;
If you select topic 4, you can only select January of the same year ?? In January of the same year, (January ?? In July), query by quarter. Otherwise, an error occurs.
If you select column 5, you can select 01-04. the query results show the records of the 01-03 month. if you query 02-04, an error is returned. if you query 01-07, the query results contain two 01--records, which are quarterly queries.
How should I modify it in \ web \ e \ search \ index. php?


Reply to discussion (solution)

Require ("../class/connect. php ");
Require ("../class/db_ SQL .php ");
Require ("../data/dbcache/class. php ");
Require ("../class/q_functions.php ");
Echeckclosemod ('search'); // Close the module
$ Link = db_connect ();
$ Empire = new mysqlquery ();


// Process keywords
Function SearchDoKeyboardVar ($ keyboard ){
$ Keyboard = RepPostVar2 (trim ($ keyboard ));
$ Keyboard = str_replace ('','', $ keyboard );
Return $ keyboard;
}

// Return SQL
Function SearchDoKeyboard ($ f, $ hh, $ keyboard ){
$ Where = '';
$ Keyboard = SearchDoKeyboardVar ($ keyboard );
If (empty ($ keyboard ))
{
Return "";
}
If (! Empty ($ hh ))
{
If ($ hh = 'Lt ') // less
{
$ Where = $ f. "<'". $ keyboard ."'";
}
Elseif ($ hh = 'GT ') // greater
{
$ Where = $ f. "> '". $ keyboard ."'";
}
Elseif ($ hh = 'EQ ') // equal
{
$ Where = $ f. "= '". $ keyboard ."'";
}
Elseif ($ hh = 'le') // less than or equal
{
$ Where = $ f. "<= '". $ keyboard ."'";
}
Elseif ($ hh = 'ge') // equal to or greater
{
$ Where = $ f. "> = '". $ keyboard ."'";
}
Elseif ($ hh = 'ne ') // not equal
{
$ Where = $ f. "<> '". $ keyboard ."'";
}
Elseif ($ hh = 'in') // contains
{
$ Kr = explode ('', $ keyboard );
$ Kcount = count ($ kr );
$ Kbs = '';
$ Dh = '';
For ($ I = 0; $ I <$ kcount; $ I ++)
{
If (empty ($ kr [$ I])
{
Continue;
}
If ($ kbs)
{
$ Dh = ',';
}
$ Kbs. = $ dh. "'". $ kr [$ I]. "'";
}
If ($ kbs)
{
$ Where = $ f. "IN (". $ kbs .")";
}
Else
{
Return '';
}
}
Elseif ($ hh = 'BT ') // range
{
$ Keyboard = ltrim ($ keyboard );
If (! Strstr ($ keyboard ,''))
{
Return '';
}
$ Kr = explode ('', $ keyboard );
If (! Trim ($ kr [0]) |! Trim ($ kr [1])
{
Return '';
}
$ Where = $ f. "between'". $ kr [0]. "'and'". $ kr [1]. "'";
}
Else // similar
{
$ Where = $ f. "LIKE '%". str_replace ("", "%", $ keyboard). "% '";
}
}
Else
{
$ Where = $ f. "LIKE '%". str_replace ("", "%", $ keyboard). "% '";
}
Return $ where;
}

// Variable
If ($ _ GET ['searchget'] = 1)
{
$ _ POST = $ _ GET;
}

$ Ip = egetip ();
$ Searchtime = time ();
$ Getvar = $ _ POST ['getvar'];
If (empty ($ getvar ))
{
$ Getfrom = "history. go (-1 )";
$ Dogetvar = '';
}
Else
{
$ Getfrom = ".../../search /";
$ Dogetvar = "& getvar = 1 ";
}
// Search user groups
If ($ public_r ['searchgroupid'])
{
$ Export archgroupid = $ public_r ['searchgroupid'];
@ Include ("../data/dbcache/MemberLevel. php ");
$ Searchgroupid = (int) getcvar ('mlgroupid ');
If ($ level_r [$ searchgroupid] [level] <$ level_r [$ incluarchgroupid] [level])
{
Printerror ("NotLevelToSearch", $ getfrom, 1 );
}
}
// Search interval
$ Lastsearchtime = getcvar ('lastsearchtime ');
If ($ lastsearchtime)
{
If ($ searchtime-$ lastsearchtime <$ public_r [searchtime])
{
Printerror ("SearchOutTime", $ getfrom, 1 );
}
}
// Search for fields
$ Searchclass =$ _ POST ['show'];
If (empty ($ searchclass) | strstr ($ searchclass ,""))
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
// Time range
$ Add = '';
$ Addtime = '';
$ Sssqqyear = $ _ POST ['sssq _ Q_YEAR '];
$ Sssqqmonth = $ _ POST ['sssq _ Q_MONTH '];
$ Sssqzyear = $ _ POST ['sssq _ Z_YEAR '];
$ Sssqzmonth = $ _ POST ['sssq _ Z_MONTH '];
$ Starttime = "$ sssqqyear". "-". "$ sssqqmonth". "-01 ";
If (empty ($ starttime ))
{
$ Starttime = "0000-00-00 ";
}
$ Endtime = "$ sssqzyear". "-". "$ sssqzmonth". "-01 ";
If (empty ($ endtime ))
{
$ Endtime = "0000-00-00 ";
}
If ($ endtime! = "0000-00-00 ")
{
$ Addtime = "and (newstime '". to_time ($ starttime. "00:00:00 "). "'and '". to_time ($ endtime. "23:59:59 "). "')";
}
// Jiage
$ Addprice = '';
$ Startprice = (int) $ _ POST ['startprice'];
$ Endprice = (int) $ _ POST ['endprice'];
If ($ endprice)
{
$ Addprice = "and (price BETWEEN". $ startprice. "and". $ endprice .")";
}
// Search for columns and tables
$ Classid = RepPostVar ($ _ POST ['classid ']);
$ S_tbname = RepPostVar ($ _ POST ['tbname']);
$ S_tempid = (int) $ _ POST ['classid '];
$ Trueclassid = 0;
If ($ classid) // by topic
{
If (strstr ($ classid, ",") // multiple columns
{
$ Son_r = sys_ReturnMoreClass ($ classid, 1 );
$ Trueclassid = $ son_r [0];
$ Add. = 'and ('. $ son_r [1]. ')';
}
Else
{
$ Trueclassid = intval ($ classid );
$ Add. = $ class_r [$ trueclassid] [islast]? "And classid = '$ trueclassid'": "and". ReturnClass ($ class_r [$ trueclassid] [sonclass]);
}
$ Tbname = $ class_r [$ trueclassid] [tbname];
$ Modid = $ class_r [$ trueclassid] [modid];
}
Elseif ($ s_tbname) // by data table
{
$ Tbnamenum = $ empire-> gettotal ("select count (*) as total from {$ dbtbpre} enewstable where tbname = '$ s_tbname 'limit 1 ");
If (! $ Tbnamenum)
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
$ Tbname = $ s_tbname;
// Model id
$ Thestemp_r = $ empire-> fettings ("select modid from". GetTemptb ("enewssearchtemp"). "where tempid = '$ s_tempid '");
If (empty ($ thestemp_r ['modid'])
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
$ Modid = $ thestemp_r ['modid'];
}
Else
{
$ Tbname = $ public_r ['tbname'];
$ Modid = 0;
}
// The table does not exist.
If (empty ($ tbname ))
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
// Topic
$ Ztid = RepPostVar ($ _ POST ['ztid']);
$ Trueztid = 0;
If ($ ztid)
{
If (strstr ($ ztid, ",") // multiple topics
{
$ Son_r = sys_ReturnMoreZt ($ ztid );
$ Trueztid = $ son_r [0];
$ Add. = 'and ('. $ son_r [1]. ')';
}
Else
{
$ Trueztid = intval ($ ztid );
$ Add. = "and ztid like '% |". $ trueztid. "| % '";
}
}
// Member
$ Member = $ _ POST ['member'];
If ($ member = 1)
{
$ Add. = 'and ismember = 1 ';
}
Elseif ($ member = 2)
{
$ Add. = 'and ismember = 0 ';
}
// Model
$ Tempr = array ();
If (empty ($ class_r [$ trueclassid] [searchtempid])
{
If (empty ($ modid ))
{
$ Tempr = $ empire-> fettings ("select modid from". GetTemptb ("enewssearchtemp"). "where isdefault = 1 limit 1 ");
}
Else
{
$ Tempr [modid] = $ modid;
}
}
Else
{
$ Tempr [modid] = $ modid;
}

// Keyword
$ Keyboard =$ _ POST ['keyboard'];
$ Keyboardone = 0;
If (is_array ($ keyboard ))
{}
Elseif (strstr ($ keyboard ,','))
{
$ Keyboard = explode (',', $ keyboard );
}
Else
{
$ Keyboard = trim ($ keyboard );
$ Len = strlen ($ keyboard );
If ($ len <$ public_r [min_keyboard] | $ len> $ public_r [max_keyboard])
{
Printerror ("MinKeyboard", $ getfrom, 1 );
}
$ Keyboardone = 1;
}

// Symbol
$ Hh = $ _ POST ['HH'];
$ Hhone = 0;
If (is_array ($ hh ))
{}
Elseif (strstr ($ hh ,','))
{
$ Hh = explode (',', $ hh );
}
Else
{
$ Hhone = 1;
}

// Field
If (! Is_array ($ searchclass ))
{
$ Searchclass = explode (',', $ searchclass );
}

$ Andor = $ _ POST ['ands'];
$ Andor = 'and '? 'AND': 'or ';

$ Mr = $ empire-> fettings ("select searchvar, tbname from {$ dbtbpre} enewsmod where mid = '$ tempr [modid]'");
If (! Strstr ($ mr [searchvar], ", price,") // whether the price is included
{
$ Addprice = "";
$ Startprice = 0;
$ Endprice = 0;
}
// Search for special fields
$ Mr [searchvar]. = 'id, keyboard, userid, username ,';
$ Where = '';
$ Newsearchclass = '';
$ Count = count ($ searchclass );
For ($ I = 0; $ I <$ count; $ I ++)
{
If (empty ($ searchclass [$ I])
{
Continue;
}
$ Searchclass [$ I] = str_replace (',', '', $ searchclass [$ I]);
If (! Strstr ($ mr [searchvar], ",". $ searchclass [$ I]. ",")
{
Continue;
}
$ Searchclass [$ I] = RepPostVar ($ searchclass [$ I]);
$ Dh = empty ($ newsearchclass )? '':',';
$ Newsearchclass. = $ dh. $ searchclass [$ I];
$ Dohh = $ hhone = 1? $ Hh: $ hh [$ I];
$ Dokeyboard = $ keyboardone = 1? $ Keyboard: $ keyboard [$ I];
$ Onewhere = SearchDoKeyboard ($ searchclass [$ I], $ dohh, $ dokeyboard );
If ($ onewhere)
{
$ Or = empty ($ where )? '':''. $ Andor .'';
$ Where. = $ or. '('. $ onewhere .')';
}
}
// Parameter error
If (empty ($ newsearchclass ))
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
If ($ where)
{
$ Add. = 'and ('. $ where .')';
}
$ Allwhere = $ add. $ addtime. $ addprice;
$ Keyboard = $ keyboardone = 1? SearchDoKeyboardVar ($ keyboard ):'';
$ Andsql = addslashes ($ allwhere );
If (strlen ($ newsearchclass)> 250 | strlen ($ classid)> 200 | strlen ($ andsql)> 3000 | strlen ($ keyboard)> 100 | strlen ($ ztid)> 200)
{
Header ("Location: result /? Searchid = 0 ". $ dogetvar );
Exit ();
}
// Verification code
$ Checkpass = md5 ($ allwhere. $ tbname );
$ Query = "select count (*) as total from {$ dbtbpre} ecms _". $ tbname. "where checked = 1". $ allwhere;
$ Search_r = $ empire-> fettings ("select searchid from {$ dbtbpre} enewssearch where checkpass = '$ checkpass' limit 1 ");
$ Searchid = $ search_r [searchid];
// Sort
$ Orderby = RepPostVar ($ _ POST ['orderby']);
$ Myorder = (int) $ _ POST ['myorder'];
If ($ orderby)
{
$ Orderr = ReturnDoOrderF ($ tempr [modid], $ orderby, $ myorder );
$ Orderby = $ orderr ['returnf '];
}
Else
{
$ Orderby = 'newstime ';
}
// Historical Records
If ($ searchid)
{
$ Search_num = $ empire-> gettotal ($ query );
$ SQL = $ empire-> query ("update {$ dbtbpre} enewssearch set searchtime = '$ searchtime', result_num =' $ search_num ', onclick = onclick + 1, orderby = '$ orderby', myorder = '$ myorder', tempid =' $ s_tempid 'where searchid =' $ searchid '");
If (empty ($ search_num ))
{
$ Searchid = 0;
}
}
Else
{
$ Search_num = $ empire-> gettotal ($ query );
If (empty ($ search_num ))
{
$ Searchid = 0;
}
Else
{
$ Iskey = $ keyboardone = 1? ;
$ SQL = $ empire-> query ("insert into {$ dbtbpre} enewssearch (searchtime, keyboard, searchclass, result_num, searchip, classid, onclick, orderby, myorder, checkpass, tbname, tempid, iskey, andsql, trueclassid) values ('$ searchtime',' $ Keyboard', '$ newsearchclass', '$ search_num', '$ IP',' $ classid ', 1, '$ orderby', '$ myorder',' $ checkpass', '$ tbname',' $ s_tempid ',' $ iskey', '$ andsql ', '$ trueclassid ')");
$ Searchid = $ empire-> lastid ();
}
}
// Set the last search time
$ Set1 = esetcookie ("lastsearchtime", $ searchtime, $ searchtime + 3600*24 );
Db_close ();
$ Empire = null;
Header ("Location: result /? Searchid = $ searchid ". $ dogetvar );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.