[求助]关于检索查询和MYSQL数据库的一些问题
hittle2008
![]()
|
1#
hittle2008 发表于2008-03-30
[求助]关于检索查询和MYSQL数据库的一些问题
1.为避免Word文件中原有字段结构的大幅度调整,如何将数据库内新增字段改成最后一个字段。
2.检索结果页框架高度太低,请加高。如何设法取消此框架。 3.Cross-corpus Full Text Search中检索全部由小写字母开头或全部由大写字母开头的词组(如Secretary General)时,词组中每一个单词开头字母大小写与所检索的词组每一个单词开头字母大小写不一致时仍检索不出,如键入secretary general、Secretary general和secretary General均检索不到结果,怎么解决这种大小写区分的问题? 4.键入小写china,检索出7个结果,其中只有一个有效,另外6个是网址。(键入大写China,可检索出28个结果。)怎么解决? 5. 怎么解决检索结果中带半角方括号的检索词(R)屏蔽问题:例如,在Cross-corpus Full Text Search 检索“[信息产业]”,会返回40条结果,只是每条结果的中文部分都有“财漯B>??漯B>??告”等形式的乱码而已。 6.怎么解决键入两个现在设的通配符(%%),会有太多的检索结果返回 (2059 Results) 。为与大部分数据库检索脚本所用的通配符一致,请用下划线(_)和*.*替代%来作检索通配符:下划线替代一个英文单词或一个汉字,*.*替代任意个英文单词或汉字。 7.如何在Term Bank Search的右边加上一个下拉框,框内内容为:[农业]、[经贸]、[金融]、[科技]、[信息产业]、[生命科学]、[能源]、[交通]、[等. 用户选择下拉框中任一检索选项时,PHP在R为相应标签的术语条目中进行检索。 8. 检索结果页第一行除注明关键词外,还要注明所检索的出处。具体格式为(例): Translation Corpus Search for “air”. Search Results: 4. Close 9. Term Bank Search、New Words Corpus Search和Translation Corpus Search检索结果页框架宽度和高度应统一,顶部的标题行字号改小,字体用Arial,如: English Term English Term's Abbr Chinese Term Chinese Term's Abbr 10.有些例证过长,显示时可否适当限制(如取检索命中词前后各200个汉字或英语单词)? 11.(原16条)现在的检索结果显示时未排序,是否能加进排序(比如先按检索词左边第一个词的拼音顺序,然后再按检索词右边第一个词的拼音顺序升序排序),以便让使用者能按顺序快速查找检索词与其他词的搭配方式. 12. 解决英文检索结果的回行问题。 13. 检索结果和详细结果页的字体改小(9 或9.5 pt)。用户检索结果限制数设为100条,每页显示50条结果。 CODE 1: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script> function SubmitQuery(){ var radioNames = new Array( "qyTBS", "qyNWS", "qyTCE", "qyCCFT");//, //"qyECS" for (i=0; i<radioNames.length; i++){ var radioBox = document.getElementById(radioNames); if (radioBox.checked){ document.getElementById("queryType").value = radioNames; }; } /* document.getElementById("queryField").value = document.getElementById("selField").value; */ document.getElementById("frmQuery").submit(); } </script> <title>TCS</title> <style type="text/css"> <!-- .STYLE4 {font-size: 16px; font-weight: bold; } .STYLE8 {font-size: 30px} .STYLE9 {font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #0000CC; } .STYLE10 {font-size: small} --> </style> </head> <body > <!--main frame--> <div style="text-align:left;width: 711px; margin-left: auto; margin-right: auto; height:527px"> <!--title frame--> <div style="text-align:center; "> <pre style="color:#0000CC; font-size:x-large; font-weight:bold; font-family:Arial; margin-top:12pt; margin-bottom:0">E/C & C/E Translation Corpus Suite (TCS)</pre> <p class="STYLE9" style="margin-top: 5pt">Term Bank, New Words Corpus, and Translation Corpus Search </p> </div> <!--query frame--> <div style="color:#0000CC;"> <p> <form id="frmQuery" action="getResults.php" method="GET" target="_blank_"> <input id="queryType" type="hidden" name="queryType" /> <input id="queryField" type="hidden" name="queryField" /> <input type="text" name="querykeyWord" value="Type search word(s) here..." onFocus="this.select();" size="30" /> <input type="button" value="Query" onClick="SubmitQuery();" /> </form> <hr /> <table width="701"> <tr> <td width="415" height="70" valign="middle"> <input id="qyTBS" type="radio" value="Term Bank Search" name="queryType" /> <label>Term Bank Search</label> <br /> <input id="qyNWS" type="radio" value="New Words Search" name="queryType" /> <label>New Words Corpus Search</label> <br /> <input id="qyTCE" type="radio" value="Translation Corpus English" name="queryType" checked /> <label>Translation Corpus </label>Search <br /> <span class="STYLE8"> </span> <input id="qyCCFT" type="radio" value="Cross-Corpus Full Text" name="queryType" /> <label>Cross-corpus Full Text Search</label> <span class="STYLE8"> <label> </label> </span><br /> <!--input id="qyECS" type="radio" value="Editors Comprehensive Search" name="queryType" /> <label>Editors Comprehensive Search</label--> <br /> </td> <td height="70" style="width:278px; text-align:center; vertical-align:top"> </td> </tr> </table> <br /> </div> <!--readme frame--> <div class="STYLE10" style="width:712px; margin-left: auto; margin-right:auto; text-align:left;color:#0000CC; height:190px"> <p style="margin-top: -2px">This corpus suite (TCS) was designed to help English/Chinese (E/C) and Chinese/English (C/E) translators and terminologists to locate equivalent terms and new words in Chinese and English and equivalent/idiomatic translations between the two languages, and to help linguists and Translation Studies researchers to study E/C and C/E translation. It consists of a term bank, a new words corpus, and a translation corpus. You can key in either Chinese or English in the search box to find relevant information. TCS's search engine supports wildcard file searches. The wildcard character accepted by the engine is "%", which can be used in place of a stretch of text of any length within a field. To facilitate search for other categories of information, a cross-corpus full-text search box is also provided on this page. </p> <p>The suite is now in its test stage, with a small test sample adopted. For each search session the displayed search results will be limited to 100. Any comments or suggestions are welcome and should be addressed to keping00Atyahoo.com.</p> </div> <hr /> <p class="STYLE4" style="color:#0000CC; size:14px; text-align:center; font-family:Arial, Helvetica, sans-serif; margin-top:6px; margin-bottom:0"> <font size="2">Nanjing University Language and Translation Technologies Group (NU/LTTG)</font></p> <p class="STYLE4" style="color:#0000CC; size:14px; text-align:center; font-family:Arial, Helvetica, sans-serif; margin-top:6px; margin-bottom:0"> <font size="2">2008 All rights reserved</font></p> </div> </body> </html> CODE1 CODE2: <?php $querykeyWord = $_REQUEST["querykeyWord"]; $queryType = $_REQUEST["queryType"]; $queryField = $_REQUEST["queryField"]; //request validation if (is_null ($querykeyWord)){ echo "Invalid request!"; return; } if (is_null ($queryType)){ echo "Invalid request!"; return; } //chinese or enghlish if (preg_match ("/([\xC0-\xFF][\x80-\xBF]+)+/", $querykeyWord)) $langType = "CHS"; else $langType = "EN"; //supporting files require "config.php"; require "mods.php"; $tableLayout = new VTableLayout(); if ($queryType == "qyTBS"){ //Term Bank Search if ($langType == "EN"){ $tableLayout->currentSchema = new VTblTBS(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } else{ $tableLayout->currentSchema = new VTblTBSC(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } } elseif ($queryType == "qyNWS"){ //New words Search if ($langType == "EN"){ $tableLayout->currentSchema = new VTblNWS(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } else{ $tableLayout->currentSchema = new VTblNWSC(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } } elseif ($queryType == "qyTCE"){ //Translation Corpus Search if ($langType == "EN"){ $tableLayout->currentSchema = new VTblTCE(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } else{ $tableLayout->currentSchema = new VTblTCEC(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } } elseif ($queryType == "qyCCFT"){ $tableLayout->currentSchema = new VTblCCFT(); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } elseif ($queryType == "qyECS"){ $tableLayout->currentSchema = new VTblECS($queryField); $tableLayout->currentSchema->queryKeyWord = $querykeyWord; } else{ echo "Invalid request!"; return; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style> a:link{ color:#0000CC; text-decoration:none; } a:visited{ color:#0000CC;; text-decoration:none; } a:hover{ color:red; text-decoration:solid; } </style> <script> </script> <title>E/C & C/E Translation Corpus Suite (TCS)</title> </head> <body > <!--main frame--> <div style="text-align:left;width: 780px; margin-left: auto; margin-right: auto;"> <!--title frame--> <div> <p style="color:#0000CC; font-size:24px; font-weight:bold; font-family:Arial; text-align:center;">E/C & C/E Translation Corpus Suite (TCS)</p> <p style="font-size: 14px; font-weight:bold;color:#0000CC;text-align:center;">Term Bank, New Words Corpus, and Translation Corpus Search </p> <p style="color:#0000CC;"> The Key word is: <span style="text-decoration:underline; font-weight:bold;"><?php echo $querykeyWord; ?> (<span id="RecordCount">0</span> Results)</span> <br /> <a href="javascript:window.close();">Close</a> </p> </div> <hr /> <!--results frame--> <div style="height:300px; overflow: auto;"> <?php $tableLayout->beginOutput("background-color: #E0F0FF;word-wrap: break-word; word-break: break-all;table-layout:fixed;"); $totalRowCount = $tableLayout->outputTableBody(); $tableLayout->endOutput(); // echo "<script>"; echo "document.getElementById(\"RecordCount\").innerHTML=\""; echo $totalRowCount; echo "\";</script>\n"; ?> </div> <hr /> <p style="color:#0000CC; size:14px; text-align:center; font-family:'Courier New', Courier, mono; ">Nanjing University Language and Translation Technologies Group (NU/LTTG) 2007 All rights reserved. </p> </div> </body> </html> CODE2 CODe 3: <?php require 'config.php' ; function utf8_substr($str,$from,$len){ return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$from.'}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$len.'}).*#s','$1',$str); } $id = $_REQUEST["id"]; if (is_int($id)){ echo "Bad request, try again!"; return; } //生成对应的查询语句 $keyWord = $_REQUEST["key"]; //$word=utf8_substr($word,0,20); $sql = "select * from ". $dbTable ." where ID = ". $id ." ; "; //开始查询 //Connect to the database server $link = mysql_connect($dbServer, $dbUsrName, $dbUsrPwd) or die("Could not connect: " . mysql_error()); //set encoding for utf-8 mysql_query("SET NAMES 'UTF8'"); //Connected successfully, select the database mysql_select_db($dbName) or die("ERROR:" . mysql_error()); $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if ($num_rows <= 0){ echo "<center>Sorry, the id <strong>'". $id ."'</strong> hasn't been gathered in our database, try another one please:<br /><a href='./'>Return</a></center>"; return; } //取查询结果 //$i = mysql_num_fields($result); //$field = mysql_fetch_field($result,9-$i); //$field->name $fields = array( "CT" => "Chinese Term" ,"CTA" => "Chinese Term's Abbr." ,"R" => "Registers" ,"ET" => "English Term" ,"ETA" => "English Term's Abbr." ,"CDE" => "Chinese Definitions/Examples" ,"EDE" => "English Definitions/Examples" ,"EDET" => "English Definitions/Examples' Translation" ,"CCR" => "Chinese Cross-references" ,"ECR" => "English Cross-references" ,"DFC" => "Date of First Compilation" ,"ETPF" => "English Term's Parallel Forms in Other European Languages" ,"ID" => "ID Number" ); $row = mysql_fetch_array($result, MYSQL_ASSOC); ?> <html> <head> <style type="text/css"> a:visited{ color:black; text-decoration:none; } a:hover{ color:red; text-decoration:none; } a:link{ color:black; text-decoration:none; } .STYLE2 { font-family: Arial, Helvetica, sans-serif; font-size: 20pt; color: #2C00AE; } .STYLE1 { font-family: "Arial"; font-size: 10.5pt; color: #2C00AE; } } </style> </head> <title> E/C & C/E Translation Corpus Suite (TCS) </title> <body leftmargin="0" topmargin="0"> <a href="javascript:history.go(-1)">Go Back</a> <div align="center" class="STYLE2">Detailed Search Result </div> <center> <table> <?php foreach ($fields as $field => $fieldname){ echo '<tr>'; echo '<td width="200" align="left" bgcolor="#cce0ff"><span class="STYLE1">' . $fieldname . "</span></td>"; $data = $row[$field];//data to highLight $keys = split("%+", $keyWord); $keywordReg = ""; foreach ($keys as $key){ $keywordReg.= $key; $keywordReg.= ".*"; } $keywordReg = substr($keywordReg, 0, strlen($keywordReg)-2); @eregi($keywordReg, $data, $regs); $hilightPreFormat = "<B style=\"color:red;\">"; $hilightSufFormat = "</B>"; $data = str_replace($regs[0], $hilightPreFormat.$regs[0].$hilightSufFormat, $data); echo '<td width="850" align="left" bgcolor="#cce0ff">' . $data . "</td>"; echo '</tr>'; } //Close the link to the server mysql_free_result($result); mysql_close($link); ?> </table> </center> </div> </body> </html> CODE3 CODE 4: <?php require 'config.php' ; //Connect to the database server $link = mysql_connect($dbServer, $dbUsrName, $dbUsrPwd) or die("Could not connect: " . mysql_error()); //set encoding for utf-8 mysql_query("SET NAMES 'UTF8'"); //Connected successfully, select the database mysql_select_db($dbName); $contents = ""; $handle = fopen('./TCS.sql', 'r' ); do { $data = fread($handle, 1); if (strlen($data) == 0) { break; } if ($data == "\n"){ mysql_query($contents); $contents = ""; } else{ $contents .= $data; } } while(true); fclose ($handle); mysql_close($link); ?> CODE 4 CODE 5: <?php function inject_check($sql_str) { return eregi("^(.*'.*)+$", $sql_str); } class VTblSchema { var $sqlStatement; var $headerNames; var $fieldNames; var $colWidths; var $hightlightColumnNum; function setHeaderNames($para){ $this->headerNames = split("\t+", $para); } function setFieldNames($para){ $this->fieldNames = split("\t+", $para); } function setColWidths($para){ $this->colWidths = split("\t+", $para); } function initializeContent(){ $this->sqlLink = mysql_connect($GLOBALS["dbServer"], $GLOBALS["dbUsrName"], $GLOBALS["dbUsrPwd"]) or die("Could not connect: " . mysql_error()); mysql_query("SET NAMES 'utf8'"); mysql_select_db($GLOBALS["dbName"]); } function releaseContent(){ @mysql_free_result($this->sqlResult); mysql_close($this->sqlLink); } } class VTblTBS extends VTblSchema{ var $queryKeyWord; var $alterWords; var $alterWordPointer; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblTBS(){ $str = "English Term English Term's Abbr Chinese Term Chinese Term's Abbr"; $this->setHeaderNames($str); $str = "ET ETA CT CTA"; $this->setFieldNames($str); $str = "280px 100px 280px 100px"; $this->setColWidths($str); $this->hightlightColumnNum = 0; $this->alterWordPointer = 0; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; //get words to repalce $keywords = ereg_replace(" ", "", $keywords); $keywords = split("%+", $this->queryKeyWord); foreach ($keywords as $key){ $this->alterWords[] = Array($key, $key); $this->alterWords[] = Array($key, $key . "ed"); $this->alterWords[] = Array($key, $key . "s"); $this->alterWords[] = Array($key, $key . "ing"); if ($key{strlen($key) - 1} == "e" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ing"); $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ed"); } if ($key{strlen($key) - 1} == "h" || $key{strlen($key) - 1} == "s" || $key{strlen($key) - 1} == "x" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "es"); } $sqlTemp = "select alterwords from alterwords where word='" . $key . "';"; $result = mysql_query($sqlTemp); if (mysql_num_rows($result)){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $splitAlterWords = split(",", $row["alterwords"]); foreach ($splitAlterWords as $splitAlterWord){ $this->alterWords[] = Array($key, $splitAlterWord); } } } mysql_free_result($result); } // print_r ($this->alterWords); } //start to prepare a new query //replace the queryKeyWord first while(true){ if ($this->alterWordPointer >= count($this->alterWords)){ return 0; } $this->queryKeyWordTemp = ereg_replace( $this->alterWords[$this->alterWordPointer][0], $this->alterWords[$this->alterWordPointer][1], $this->queryKeyWord ); $this->alterWordPointer = $this->alterWordPointer+1; $sqlStatement = "select ID, ET, ETA, CT, CTA from ".$GLOBALS["dbTable"]." where ET like '" . $this->queryKeyWordTemp . " %' or ET like '% " . $this->queryKeyWordTemp . "' or ET like '% " . $this->queryKeyWordTemp . " %' or ET like '" . $this->queryKeyWordTemp . "' limit 0,200;"; //echo $sqlStatement . "<br>"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWordTemp; if ($this->sqlResult){ return 1; } }//while(true) } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTblTBSC class VTblTBSC extends VTblSchema{ var $queryKeyWord; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblTBSC(){ $str = "Chinese Term Chinese Term's Abbr English Term English Term's Abbr"; $this->setHeaderNames($str); $str = "CT CTA ET ETA"; $this->setFieldNames($str); $str = "280px 100px 280px 100px"; $this->setColWidths($str); $this->hightlightColumnNum = 1; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; $sqlStatement = "select ID, ET, ETA, CT, CTA from ".$GLOBALS["dbTable"]." where CT like '%" . $this->queryKeyWord . "%' limit 0,200;"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWord; return mysql_num_rows($this->sqlResult); } return 0; } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } class VTblNWS extends VTblSchema{ var $queryKeyWord; var $alterWords; var $alterWordPointer; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblNWS(){ $str = "English Term English Term's Abbr Chinese Term Chinese Term's Abbr"; $this->setHeaderNames($str); $str = "ET ETA CT CTA"; $this->setFieldNames($str); $str = "280px 100px 280px 100px"; $this->setColWidths($str); $this->hightlightColumnNum = 0; $this->alterWordPointer = 0; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; //get words to repalce $keywords = ereg_replace(" ", "", $keywords); $keywords = split("%+", $this->queryKeyWord); foreach ($keywords as $key){ $this->alterWords[] = Array($key, $key); $this->alterWords[] = Array($key, $key . "ed"); $this->alterWords[] = Array($key, $key . "s"); $this->alterWords[] = Array($key, $key . "ing"); if ($key{strlen($key) - 1} == "e" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ing"); $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ed"); } if ($key{strlen($key) - 1} == "h" || $key{strlen($key) - 1} == "s" || $key{strlen($key) - 1} == "x" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "es"); } $sqlTemp = "select alterwords from alterwords where word='" . $key . "';"; $result = mysql_query($sqlTemp); if (mysql_num_rows($result)){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $splitAlterWords = split(",", $row["alterwords"]); foreach ($splitAlterWords as $splitAlterWord){ $this->alterWords[] = Array($key, $splitAlterWord); } } } mysql_free_result($result); } // print_r ($this->alterWords); } //start to prepare a new query //replace the queryKeyWord first while(true){ if ($this->alterWordPointer >= count($this->alterWords)){ return 0; } $this->queryKeyWordTemp = ereg_replace( $this->alterWords[$this->alterWordPointer][0], $this->alterWords[$this->alterWordPointer][1], $this->queryKeyWord ); $this->alterWordPointer = $this->alterWordPointer+1; $sqlStatement = "select ID, ET, ETA, CT, CTA from ".$GLOBALS["dbTable"]." where (ET like '" . $this->queryKeyWordTemp . " %' or ET like '% " . $this->queryKeyWordTemp . "' or ET like '% " . $this->queryKeyWordTemp . " %' or ET like '" . $this->queryKeyWordTemp . "') and Old <> 'True' limit 0,200;"; //echo $sqlStatement . "<br>"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWordTemp; if ($this->sqlResult){ return 1; } }//while(true) } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTblNWSC class VTblNWSC extends VTblSchema{ var $queryKeyWord; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblNWSC(){ $str = "Chinese Term Chinese Term's Abbr English Term English Term's Abbr"; $this->setHeaderNames($str); $str = "CT CTA ET ETA"; $this->setFieldNames($str); $str = "280px 100px 280px 100px"; $this->setColWidths($str); $this->hightlightColumnNum = 1; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; $sqlStatement = "select ID, ET, ETA, CT, CTA from ".$GLOBALS["dbTable"]." where (CT like '%" . $this->queryKeyWord . "%') and Old <> 'True' limit 0,200;"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWord; return mysql_num_rows($this->sqlResult); } return 0; } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTblTCE class VTblTCE extends VTblSchema{ var $queryKeyWord; var $alterWords; var $alterWordPointer; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblTCE(){ $str = "English Definitions/Examples English Definitions/Examples’ Transl Chinese Definitions/Examples"; $this->setHeaderNames($str); $str = "EDE EDET CDE"; $this->setFieldNames($str); $str = "280px 280px 200px"; $this->setColWidths($str); $this->alterWordPointer = 0; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; //get words to repalce $keywords = ereg_replace(" ", "", $keywords); $keywords = split("%+", $this->queryKeyWord); foreach ($keywords as $key){ $this->alterWords[] = Array($key, $key); $this->alterWords[] = Array($key, $key . "ed"); $this->alterWords[] = Array($key, $key . "s"); $this->alterWords[] = Array($key, $key . "ing"); if ($key{strlen($key) - 1} == "e" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ing"); $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ed"); } if ($key{strlen($key) - 1} == "h" || $key{strlen($key) - 1} == "s" || $key{strlen($key) - 1} == "x" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "es"); } $sqlTemp = "select alterwords from alterwords where word='" . $key . "';"; $result = mysql_query($sqlTemp); if (mysql_num_rows($result)){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $splitAlterWords = split(",", $row["alterwords"]); foreach ($splitAlterWords as $splitAlterWord){ $this->alterWords[] = Array($key, $splitAlterWord); } } } mysql_free_result($result); } // print_r ($this->alterWords); } //start to prepare a new query //replace the queryKeyWord first while(true){ if ($this->alterWordPointer >= count($this->alterWords)){ return 0; } $this->queryKeyWordTemp = ereg_replace( $this->alterWords[$this->alterWordPointer][0], $this->alterWords[$this->alterWordPointer][1], $this->queryKeyWord ); $this->alterWordPointer = $this->alterWordPointer+1; $sqlStatement = $sqlStatement = "select CDE,EDE,EDET from ".$GLOBALS["dbTable"]." where (EDE like '" . $this->queryKeyWordTemp . "' or EDE like '" . $this->queryKeyWordTemp . " %' or EDE like '% " . $this->queryKeyWordTemp . " %' or EDE like '% " . $this->queryKeyWordTemp . "') and length(EDET) <> 0 limit 0,200;"; //echo $sqlStatement . "<br>"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWordTemp; if ($this->sqlResult){ return 1; } }//while(true) } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTblTCEC class VTblTCEC extends VTblSchema{ var $queryKeyWord; var $currentKeyWord; var $sqlLink; var $sqlResult; function VTblTCEC(){ $str = "English Definitions/Examples’ Transl English Definitions/Examples Chinese Definitions/Examples"; $this->setHeaderNames($str); $str = "EDET EDE CDE"; $this->setFieldNames($str); $str = "280px 280px 200px"; $this->setColWidths($str); } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; $sqlStatement = "select ID,CDE,EDE,EDET from ".$GLOBALS["dbTable"]." where EDET like '%" . $this->queryKeyWord . "%' and length(EDE) <> 0 limit 0,200;"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWord; return mysql_num_rows($this->sqlResult); } return 0; } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTblCCFT class VTblCCFT extends VTblSchema{ var $queryKeyWord; var $currentKeyWord; var $sqlLink; var $sqlResult; var $clusterData; var $clusterDataPointer; function VTblCCFT(){ $str = "Full Text"; $this->setHeaderNames($str); $str = "txt"; $this->setFieldNames($str); $str = "780px"; $this->setColWidths($str); $clusterDataPointer=0; } function prepareQuery(){ static $next = true; $this->clusterDataPointer=0; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; $sqlStatement = "select * from ".$GLOBALS["dbTable"]." where ET like '%" . $this->queryKeyWord . "%' or ETA like '%" . $this->queryKeyWord . "%' or CT like '%" . $this->queryKeyWord . "%' or CTA like '%" . $this->queryKeyWord . "%' or R like '%" . $this->queryKeyWord . "%' or CDE like '%" . $this->queryKeyWord . "%' or EDE like '%" . $this->queryKeyWord . "%' or EDET like '%" . $this->queryKeyWord . "%' or CCR like '%" . $this->queryKeyWord . "%' or ECR like '%" . $this->queryKeyWord . "%' or DFC like '%" . $this->queryKeyWord . "%' or ETPF like '%" . $this->queryKeyWord . "%' limit 0,200;"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWord; if (mysql_num_rows($this->sqlResult)<=0) return 0; $temp = mysql_fetch_array($this->sqlResult, MYSQL_BOTH); if (!$temp) return 0; $this->clusterData["ID"] = $temp["ID"]; for ($i=1; $i<12 ;$i++){ $this->clusterData[$i] = $temp[$i]; } return 1; } else{ $temp = mysql_fetch_array($this->sqlResult, MYSQL_BOTH); if (!$temp) return 0; $this->clusterData["ID"] = $temp["ID"]; for ($i=1; $i<12 ;$i++){ $this->clusterData[$i] = $temp[$i]; } return 1; } } function getRowData(){ while (true){ if ($this->clusterDataPointer==11){ return null; } //filter //match $temp = ereg_replace("%+", ".*", $this->queryKeyWord); $b = ereg($temp, $this->clusterData[$this->clusterDataPointer++]); $b &=!ereg("^\[.+\]$", $this->clusterData[$this->clusterDataPointer-1]); if (!$b){ continue; } return Array( "ID" => $this->clusterData["ID"], "txt" => $this->clusterData[$this->clusterDataPointer-1] ); } } } //VTblECS class VTblECS extends VTblSchema{ var $queryKeyWord; var $alterWords; var $alterWordPointer; var $currentKeyWord; var $sqlLink; var $sqlResult; var $queryfieldName; function VTblECS($fieldName){ $this->queryfieldName = $fieldName; $str = $fieldName; $this->setHeaderNames($str); $str = $fieldName; $this->setFieldNames($str); $str = "780px"; $this->setColWidths($str); $this->hightlightColumnNum = 0; $this->alterWordPointer = 0; } function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; //get words to repalce $keywords = ereg_replace(" ", "", $keywords); $keywords = split("%+", $this->queryKeyWord); foreach ($keywords as $key){ $this->alterWords[] = Array($key, $key); $this->alterWords[] = Array($key, $key . "ed"); $this->alterWords[] = Array($key, $key . "s"); $this->alterWords[] = Array($key, $key . "ing"); if ($key{strlen($key) - 1} == "e" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ing"); $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "ed"); } if ($key{strlen($key) - 1} == "h" || $key{strlen($key) - 1} == "s" || $key{strlen($key) - 1} == "x" ){ $this->alterWords[] = Array($key, substr($key, 0, strlen($key)-1) . "es"); } $sqlTemp = "select alterwords from alterwords where word='" . $key . "';"; $result = mysql_query($sqlTemp); if (mysql_num_rows($result)){ while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $splitAlterWords = split(",", $row["alterwords"]); foreach ($splitAlterWords as $splitAlterWord){ $this->alterWords[] = Array($key, $splitAlterWord); } } } mysql_free_result($result); } // print_r ($this->alterWords); } //start to prepare a new query //replace the queryKeyWord first while(true){ if ($this->alterWordPointer >= count($this->alterWords)){ return 0; } $this->queryKeyWordTemp = ereg_replace( $this->alterWords[$this->alterWordPointer][0], $this->alterWords[$this->alterWordPointer][1], $this->queryKeyWord ); $this->alterWordPointer = $this->alterWordPointer+1; $sqlStatement = "select ID," . $this->queryfieldName . " from ".$GLOBALS["dbTable"]." where " .$this->queryfieldName. " like '" . $this->queryKeyWordTemp . "' or " .$this->queryfieldName. " like '" . $this->queryKeyWordTemp . " %' or " .$this->queryfieldName. " like '% " . $this->queryKeyWordTemp . " %' or " .$this->queryfieldName. " like '% " . $this->queryKeyWordTemp . "' limit 0,200;"; //echo $sqlStatement . "<br>"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWordTemp; if ($this->sqlResult){ return 1; } }//while(true) } function getRowData(){ return mysql_fetch_array($this->sqlResult, MYSQL_ASSOC); } } //VTableLayout class VTableLayout { var $currentSchema; function beginOutput($style){ echo "<table style=\"" . $style . "\" >"; } function endOutput(){ echo "</table>"; } function outputTableBody(){ //output table header $t =count($this->currentSchema->headerNames); echo "<tr style=\"background-color:#D0E0EF\">"; for ($i=0; $i<$t; $i++){ echo "<td width=\""; echo $this->currentSchema->colWidths[$i]; echo "\">"; echo $this->currentSchema->headerNames[$i]; echo "</td>"; } echo "</tr>\n"; //output table rows $this->currentSchema->initializeContent(); $rowCount = $this->currentSchema->prepareQuery(); if ($rowCount <= 0){ echo "<TR><TD align = \"center\" colspan=\"30\">nothing was found..</TD></TR>"; $this->currentSchema->releaseContent(); return; } $totalRowCount = 0; $oddRow = false; while ($rowCount){ while ($rowData= $this->currentSchema->getRowData()){ $totalRowCount++; if ($oddRow = !$oddRow){ echo "<tr>\n"; } else{ echo "<tr style=\"background-color:#FFFFFF;\">\n"; } for ($i=0; $i<$t; $i++){ echo "<td style=\"width:"; echo $this->currentSchema->colWidths[$i]; echo "; style=\"word-wrap: break-word; word-break: break-all;\">"; $data = $rowData[$this->currentSchema->fieldNames[$i]]; if ($i==0){ $keys = split("%+", $this->currentSchema->currentKeyWord); $keywordReg = ""; foreach ($keys as $key){ $keywordReg.= $key; $keywordReg.= ".*"; } $keywordReg = substr($keywordReg, 0, strlen($keywordReg)-2); @eregi($keywordReg, $data, $regs); $hilightPreFormat = "<B style=\"color:red;\">"; $hilightSufFormat = "</B>"; //hyperlink filter if ($GLOBALS["queryType"]!="qyTCE"){ echo "<a href=\"getDetail.php?id="; echo $rowData["ID"]; echo "&key="; echo $this->currentSchema->currentKeyWord; echo "\">"; $data = str_replace($regs[0], $hilightPreFormat.$regs[0].$hilightSufFormat, $data); echo $data; echo "</a>"; } else{ $data = str_replace($regs[0], $hilightPreFormat.$regs[0].$hilightSufFormat, $data); echo $data; } } else{ echo $data; } echo "</td>"; } echo "</tr>\n"; } $rowCount = $this->currentSchema->prepareQuery(); } $this->currentSchema->releaseContent(); return $totalRowCount; } } /* function prepareQuery(){ static $next = true; if ($next){ $next = false; if (inject_check($this->queryKeyWord)) return 0; $sqlStatement = "select ID, ET, ETA, CT, CTA from ".$GLOBALS["dbTable"]." where ET like '" . $this->queryKeyWord . " %' or ET like '% " . $this->queryKeyWord . "' or ET like '% " . $this->queryKeyWord . " %' or ET like '" . $this->queryKeyWord . "' limit 0,200;"; $this->sqlResult = mysql_query($sqlStatement); $this->currentKeyWord = $this->queryKeyWord; return mysql_num_rows($this->sqlResult); } return 0; } */ ?> CODE 5 |