001.
<?php
002.
003.
004.
$aColumns
=
array
(
'IDnumber'
,
'Prefix'
,
'Fname'
,
'Lname'
,
'Level'
,
'SchYear'
,
'typeArea'
,
'IDstd'
);
005.
006.
007.
$sIndexColumn
=
"IDstd"
;
008.
009.
010.
$sTable
=
"member"
;
011.
012.
013.
$gaSql
[
'user'
] =
"root"
;
014.
$gaSql
[
'password'
] =
"12345678"
;
015.
$gaSql
[
'db'
] =
"spwr"
;
016.
$gaSql
[
'server'
] =
"localhost"
;
017.
018.
019.
020.
$gaSql
[
'link'
] = mysql_pconnect(
$gaSql
[
'server'
],
$gaSql
[
'user'
],
$gaSql
[
'password'
] )
or
021.
die
(
'Could not open connection to server'
);
022.
023.
mysql_select_db(
$gaSql
[
'db'
],
$gaSql
[
'link'
] )
or
024.
die
(
'Could not select database '
.
$gaSql
[
'db'
] );
025.
026.
$sLimit
=
""
;
027.
if
( isset(
$_GET
[
'iDisplayStart'
] ) &&
$_GET
[
'iDisplayLength'
] !=
'-1'
)
028.
{
029.
$sLimit
=
"LIMIT "
.mysql_real_escape_string(
$_GET
[
'iDisplayStart'
] ).
", "
.
030.
mysql_real_escape_string(
$_GET
[
'iDisplayLength'
] );
031.
}
032.
033.
$sOrder
=
""
;
034.
if
( isset(
$_GET
[
'iSortCol_0'
] ) )
035.
{
036.
$sOrder
=
"ORDER BY "
;
037.
for
(
$i
=0 ;
$i
<
intval
(
$_GET
[
'iSortingCols'
] ) ;
$i
++ )
038.
{
039.
if
(
$_GET
[
'bSortable_'
.
intval
(
$_GET
[
'iSortCol_'
.
$i
]) ] ==
"true"
)
040.
{
041.
$sOrder
.=
$aColumns
[
intval
(
$_GET
[
'iSortCol_'
.
$i
] ) ]."
042.
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) ."
, ";
043.
}
044.
}
045.
046.
$sOrder
= substr_replace(
$sOrder
,
""
, -2 );
047.
if
(
$sOrder
==
"ORDER BY"
)
048.
{
049.
$sOrder
=
""
;
050.
}
051.
}
052.
$sWhere
=
""
;
053.
if
( isset(
$_GET
[
'sSearch'
]) &&
$_GET
[
'sSearch'
] !=
""
)
054.
{
055.
$sWhere
=
"WHERE ("
;
056.
for
(
$i
=0 ;
$i
<
count
(
$aColumns
) ;
$i
++ )
057.
{
058.
$sWhere
.=
$aColumns
[
$i
].
" LIKE '%"
.mysql_real_escape_string(
$_GET
['sSearch
'] )."%'
OR ";
059.
}
060.
$sWhere
= substr_replace(
$sWhere
,
""
, -3 );
061.
$sWhere
.=
')'
;
062.
}
063.
064.
for
(
$i
=0 ;
$i
<
count
(
$aColumns
) ;
$i
++ )
065.
{
066.
if
( isset(
$_GET
[
'bSearchable_'
.
$i
]) &&
$_GET
[
'bSearchable_'
.
$i
] ==
"true"
&&
$_GET
[
'sSearch_'
.
$i
] !=
''
)
067.
{
068.
if
(
$sWhere
==
""
)
069.
{
070.
$sWhere
=
"WHERE "
;
071.
}
072.
else
073.
{
074.
$sWhere
.=
" AND "
;
075.
}
076.
$sWhere
.=
$aColumns
[
$i
].
" LIKE '%"
.mysql_real_escape_string(
$_GET
['sSearch_
'.$i])."%'
";
077.
}
078.
}
079.
080.
$sQuery
= "
081.
SELECT SQL_CALC_FOUND_ROWS
".str_replace("
,
", "
", implode("
,
", $aColumns))."
082.
FROM
$sTable
083.
$sWhere
084.
$sOrder
085.
$sLimit
086.
";
087.
$rResult
= mysql_query(
$sQuery
,
$gaSql
[
'link'
] )
or
die
(mysql_error());
088.
089.
090.
$sQuery
= "
091.
SELECT FOUND_ROWS()
092.
";
093.
$rResultFilterTotal
= mysql_query(
$sQuery
,
$gaSql
[
'link'
] )
or
die
(mysql_error());
094.
$aResultFilterTotal
= mysql_fetch_array(
$rResultFilterTotal
);
095.
$iFilteredTotal
=
$aResultFilterTotal
[0];
096.
097.
098.
$sQuery
= "
099.
SELECT
COUNT
(
".$sIndexColumn."
)
100.
FROM
$sTable
101.
";
102.
$rResultTotal
= mysql_query(
$sQuery
,
$gaSql
[
'link'
] )
or
die
(mysql_error());
103.
$aResultTotal
= mysql_fetch_array(
$rResultTotal
);
104.
$iTotal
=
$aResultTotal
[0];
105.
106.
$output
=
array
(
107.
"sEcho"
=>
intval
(
$_GET
[
'sEcho'
]),
108.
"iTotalRecords"
=>
$iTotal
,
109.
"iTotalDisplayRecords"
=>
$iFilteredTotal
,
110.
"aaData"
=>
array
()
111.
);
112.
while
(
$aRow
= mysql_fetch_array(
$rResult
) )
113.
{
114.
$row
=
array
();
115.
116.
for
(
$i
=0 ;
$i
<
count
(
$aColumns
) ;
$i
++ )
117.
{
118.
if
(
$aColumns
[
$i
] ==
"IDstd"
)
119.
{
120.
$IDstd
=
$aRow
[
'IDstd'
];
121.
122.
$row
[] =
"<a id='PROFILE' class='fancybox' href='pop1.php?IDstd="
.
$IDstd
."' ><img src=
'media/images/view32.png'
width=
'32'
height=
'32'
title=
'ดูข้อมูล'
/></a>
123.
<a id=
'EDIT'
class
=
'fancybox'
href=
'pop1.php?IDstd=".$IDstd."'
><img src=
'media/images/edit32.png'
width=
'32'
height=
'32'
title=
'แก้ไขข้อมูล'
/></a>
124.
<a id=
'DEL'
class
=
'fancybox'
href=
'pop1.php?IDstd=".$IDstd."'
><img src=
'media/images/del32.png'
width=
'32'
height=
'32'
title=
'ลบข้อมูล'
/></a>" ;
125.
}
126.
else
if
(
$aColumns
[
$i
] !=
' '
)
127.
{
128.
129.
$row
[] =
$aRow
[
$aColumns
[
$i
] ];
130.
}
131.
}
132.
$output
[
'aaData'
][] =
$row
;
133.
}
134.
echo
json_encode(
$output
);
135.
?>