forked from Anupama-Github/rasi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
254 lines (210 loc) · 8.1 KB
/
search.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
//$aColumns = array( 'word' );
/* DB table to use */
/* include ("dbConfig.php");
$DB = new DBConfig();
$DB -> config();
$dbhandle =$DB -> conn();
//$word="da%";
$word=$_GET['more_data'];
$squery="select w.word,w.id,t.meaning,t.createdby,t.modifiedby,t.comments,t.reference,t.createdon,t.modifiedon from words w join temp_meanings t on (w.id=t.word_id and w.word like '$word%' )";
$result=mysql_query( $squery ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
$test[]=array();
$i=0;
while($aRow=mysql_fetch_array($result))
{
$test[$i++]="<input type=\"text\" name=\"wordid[]\" value=" . $aRow['id'] . " />";
//echo json_encode("<input type=\"text\" name=\"wordid[]\" value=" . $aRow['id'] . " />");
}
echo json_encode($test);
//echo json_encode( "Hello");*/
$aColumns = array( 'temp_meanings.word_id','words.word','temp_meanings.meaning','temp_meanings.createdby','temp_meanings.comments'
,'temp_meanings.reference','temp_meanings.createdon','temp_meanings.status','temp_meanings.remarks', );
$cols=array('word_id','word','meaning','createdby','comments'
,'reference','createdon','status','modifiedon');
$names=array('wordid[]','word[]','meaning[]','createdby[]','comments[]','reference[]','createdon[]','remarks[]');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "words.id";
/* DB table to use */
$sTable = array("words","temp_meanings");
/* Database connection information */
$gaSql['user'] = "root";
$gaSql['password'] = "redlotus";
$gaSql['db'] = "rasi";
$gaSql['server'] = "localhost";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* Local functions
*/
function fatal_error ( $sErrorMessage = '' )
{
header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
die( $sErrorMessage );
}
/*
* MySQL connection
*/
if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) )
{
fatal_error( 'Could not open connection to server' );
}
if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
{
fatal_error( 'Could not select database ' );
}
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = " LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
intval( $_GET['iDisplayLength'] );
// $sLimit = " LIMIT 0,1";
// $_SESSION['count']=$_GET['iDisplayLength'];
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<(count($aColumns)-2) ; $i++ )
{
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
{
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns)-1 ; $i++ )
{
if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
//$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
$sWhere .$aColumns[0]." LIKE '%".mysql_real_escape_string("da")."%' ";
}
}
/*
* SQL queries
* Get data to display
*/
/*$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable[0] join $sTable[1] on $sTable[0].id=$sTable[1].id
$sWhere
$sOrder
$sLimit
";*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable[0] join $sTable[1] on $sTable[0].id=$sTable[1].word_id ".
$sWhere. $sLimit;
// echo $sQuery;
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_error() );
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable[0] join temp_meanings on words.id=temp_meanings.word_id;
";
$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_error() );
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
);
/*$output = array(
"sEcho" => intval($_GET['sEcho']),
"aaData" => array()
);*/
$j=1;
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($cols) ; $i++ )
{
if ( $aColumns[$i] == "temp_meanings.status" )
{
/* Special output formatting for 'version' column */
$row[] = "<select name='decision[]' >
<option value='approve'>Approve</option>
<option value='reject'>Reject</option>
</select>";
}
else if ( $aColumns[$i] == "temp_meanings.word_id" )
{
/* General output */
$row[] = '<input type=hidden name= "'.$names[$i].'" value="'.$aRow[ $cols[$i] ].'" />';
// $row[]=$aRow[ $cols[$i] ];
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$row[] = '<input type=text name= "'.$names[$i].'" value="'.$aRow[ $cols[$i] ].'" />';
// $row[]=$aRow[ $cols[$i] ];
}
}
$output['aaData'][] = $row;
$j++;
}
//$output['submit']=stripslashes("<input type=\"submit\" value=\"Submit\"/>");
echo json_encode(($output));
?>