-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_dict.php
108 lines (90 loc) · 2.54 KB
/
query_dict.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
include 'config_db.php';
include 'helpers.php';
//debugger
include 'ChromePhp.php';
header('Content-type: text/html; charset=utf-8');
$term = $_GET['term'];
$chartype = $_GET['chartype'];
ChromePhp::log($chartype);
ChromePhp::log($term);
$dbh->query("SET NAMES utf8");
$sql = "SELECT *
FROM `entry`
WHERE `traditional` = '$term'
OR `simplified` = '$term'";
$exact = $dbh->query($sql);
$exact_count = $dbh->query("SELECT COUNT(*)
FROM `entry`
WHERE `traditional` = '$term'
OR `simplified` = '$term'")->fetchColumn();
$as_first = $term.'_%';
$sql = "SELECT $chartype, pinyin, english from entry
WHERE $chartype LIKE '$as_first'
ORDER BY LENGTH($chartype) ASC";
$first_result = $dbh->query($sql);
$sql = "SELECT $chartype, pinyin, english from entry
WHERE $chartype LIKE '_%$term%'
ORDER BY LENGTH($chartype) ASC";
$contains_result = $dbh->query($sql);
?>
<table class="terms">
<?php if($exact_count > 0) : ?>
<tr class="primary result">
<?php $row = $exact->fetch(); ?>
<td rowspan="<?php echo $exact_count ?>">
<span class="char main"><?php echo $row[$chartype]; ?></span>
</td>
<td>
<span class="pinyin"><?php echo pinyin_addaccents($row['pinyin']); ?></span>
</td>
<td>
<span class="english"><?php echo $row['english']; ?></span><br/>
</td>
</tr>
<?php while ($row = $exact->fetch()) : ?>
<tr class="primary result">
<td>
<span class="pinyin"><?php echo pinyin_addaccents($row['pinyin']); ?></span>
</td>
<td>
<span class="english"><?php echo $row['english']; ?></span><br/>
</td>
</tr>
<?php endwhile ?>
<?php endif ?>
<?php if($first_result) : ?>
<?php foreach(($first_result) as $row) : ?>
<tr>
<td>
<span class="char"><?php echo highlight($row[0], $term); ?></span>
</td>
<td>
<span class="pinyin">
<?php echo pinyin_addaccents($row['pinyin']); ?>
</span>
</td>
<td><?php echo $row['english']; ?></td>
</tr>
<?php endforeach ?>
<?php endif ?>
<?php if($contains_result) : ?>
<?php foreach(($contains_result) as $row) : ?>
<tr>
<td>
<span class="char"><?php echo highlight($row[0], $term); ?></span>
</td>
<td>
<span class="pinyin">
<?php echo pinyin_addaccents($row['pinyin']); ?>
</span>
</td>
<td><?php echo $row['english']; ?></td>
</tr>
<?php endforeach ?>
<?php endif ?>
</table>
</div>
<div class="tab-pane" id="all">
</div>
</div>