get_term_index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /*
  3. 查询term字典
  4. 输入单词列表
  5. 输出查到的结果
  6. */
  7. require_once "../config.php";
  8. require_once "../public/_pdo.php";
  9. $output["status"] = 0;
  10. $output["error"] = "";
  11. PDO_Connect(_FILE_DB_TERM_);
  12. if (isset($_POST["lang"])) {
  13. $lang = $_POST["lang"];
  14. } else {
  15. $output["status"] = 1;
  16. $output["error"] = "#no_param lang";
  17. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  18. exit;
  19. }
  20. if (isset($_POST["word"])) {
  21. $word = $_POST["word"];
  22. $query = "SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where word=? and language=? group by word,meaning order by co DESC";
  23. $output["data"] = PDO_FetchAll($query, array($word, $lang));
  24. } else {
  25. $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language=? group by word,meaning order by co DESC) group by word";
  26. $output["data"] = PDO_FetchAll($query, array($lang));
  27. $pos = mb_strpos($lang, "-", 0, "UTF-8");
  28. if ($pos) {
  29. $lang_family = mb_substr($lang, 0, $pos, "UTF-8");
  30. $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language like ? group by word,meaning order by co DESC) group by word";
  31. $otherlang = PDO_FetchAll($query, array($lang_family . "%"));
  32. foreach ($otherlang as $key => $value) {
  33. $output["data"][] = $value;
  34. }
  35. }
  36. }
  37. echo json_encode($output, JSON_UNESCAPED_UNICODE);