-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchword.php
64 lines (50 loc) · 2.01 KB
/
searchword.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
<?php
session_start();
$list = $_POST['list'];
$number = $_POST['number'];
include_once 'sqlhost.php';
$mysql = mysql_connect($hosting ,$username,$password);
mysql_query("use vocabulary", $mysql);
if($list == 0){
$result = mysql_query("select * from cet4 join ".$_SESSION['username']."__cet4 where mem < 3 and ".$_SESSION['username']."__cet4.word = cet4.word", $mysql);
}
else if($list == 1){
$result = mysql_query("select * from cet6 join ".$_SESSION['username']."__cet6 where mem < 3 and ".$_SESSION['username']."__cet6.word = cet6.word", $mysql);
}
else if($list == 2){
$result = mysql_query("select * from ".$_SESSION['username']." where mem < 3", $mysql);
}
$words = array();
if(mysql_num_rows($result) < $number){
echo "false";
}
else{
$numbers = range (0,mysql_num_rows($result)-1);
shuffle ($numbers);
$randlist = array_slice($numbers,0,$number);
$all = array();
for($i = 0;$i<mysql_num_rows($result);$i++){
$row = mysql_fetch_array($result, MYSQL_BOTH);
array_push($all, $row);
}
for($i = 0;$i<$number;$i++){
if($list == 2){
$word = array($all[$randlist[$i]]['word'], $all[$randlist[$i]]['property'], $all[$randlist[$i]]['explanation'], $all[$randlist[$i]]['mem']);
}
else if($list == 0){
$tmpwd = $all[$randlist[$i]]['word'];
$thismem = mysql_query("select * from ".$_SESSION['username']."__cet4 where word = '$tmpwd'", $mysql);
$tmp = mysql_fetch_array($thismem, MYSQL_BOTH);
$word = array($all[$randlist[$i]]['word'], $all[$randlist[$i]]['property'], $all[$randlist[$i]]['explanation'], $tmp['mem']);
}
else if($list == 1){
$tmpwd = $all[$randlist[$i]]['word'];
$thismem = mysql_query("select * from ".$_SESSION['username']."__cet6 where word = '$tmpwd'", $mysql);
$tmp = mysql_fetch_array($thismem, MYSQL_BOTH);
$word = array($all[$randlist[$i]]['word'],$all[$randlist[$i]]['property'], $all[$randlist[$i]]['explanation'], $tmp['mem']);
}
array_push($words, $word);
}
echo json_encode($words);
}
?>