📄 00000032.htm
字号:
// RETURN: function returns resultfield <BR> function GetQueryString($table, $searchfield, $resultfield= "ID") { <BR> // begin query string <BR> $query_string = "SELECT $resultfield FROM $table WHERE "; <BR> // get the query string <BR> $query_string .= $this->BuildQueryString($table, $searchfield); <BR> // append limit <BR> if ($this->m_start || $this->m_offset) { <BR> $query_string .= "LIMIT $this->m_start"; <BR> if($this->m_offset) <BR> $query_string .= ",$this->m_offset"; <BR> } <BR> return $query_string; <BR> } <BR> // build Query string that will return the number of rows selected <BR> function GetCountQueryString($table, $searchfield) { <BR> // begin query string <BR> $query_string = "SELECT count(*) FROM $table WHERE "; <BR> // get the query string <BR> $query_string .= $this->BuildQueryString($table, $searchfield); <BR> return $query_string; <BR> } <BR>//PRIVATE: <BR> // main function that generates the entire query <BR> function BuildQueryString($table, $searchfield) { <BR> // parse searchfields <BR> $searchfields = explode( ",", $searchfield); <BR> if(!is_array($searchfields)) <BR> $searchfields=array($searchfield); <BR> // build query for each searchfield <BR> while ($searchfield = current($searchfields)) { <BR> // uppercase do case insensitive man <BR> if (!$this->m_casematch) <BR> $searchfield = "UPPER(".$searchfield. ")"; <BR> $firstquery = true; <BR> $query_string .= "("; <BR> // build current query <BR> reset($this->m_Querys); <BR> while($query = current($this->m_Querys)) { <BR> // append logic <BR> if ($firstquery) <BR> $firstquery=false; <BR> else if ($query->m_logic == "NOT") <BR> $query_string.= "AND"; <BR> else <BR> $query_string.=$query->m_logic; <BR> // append where clause <BR> $query_string .= <BR> $this->BuildWhereClause($searchfield, $query); <BR> next($this->m_Querys); <BR> } <BR> $query_string .= ")"; <BR> if (next($searchfields)) <BR> $query_string .= "OR"; <BR> } <BR> return $query_string; <BR> } <BR> // build where clause <BR> function BuildWhereClause($searchfield, $query) { <BR> $query_string.= "("; <BR> while($word = current($query->m_words)) { <BR> if (!$this->m_casematch) <BR> $word = strtoupper($word); <BR> if ($this->m_wordmatch) <BR> $search_type = "REGEXP '[[:<:]]".$word. "[[:>:]]'"; <BR> else <BR> $search_type = "REGEXP '$word'"; <BR> if ($query->m_logic == "NOT") <BR> $query_string.= "$searchfield NOT "; <BR> else <BR> $query_string.= "$searchfield "; <BR> $query_string.= $search_type; <BR> if (next($query->m_words)) <BR> $query_string.= " OR "; <BR> } <BR> $query_string.= ")"; <BR> return $query_string; <BR> } <BR>}; <BR>?> <BR> <BR>-- <BR> <BR>人生到处知何似? <BR> 应似飞鸿踏雪泥。 <BR> 泥上偶然留指爪, <BR> 鸿飞那复计东西! <BR> <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: 162.105.37.191] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -