ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/shardiwal/attenuted_processing.php
Revision: 13
Committed: Wed Feb 2 04:17:00 2011 UTC (5 years, 3 months ago) by rakeshshardiwal
File size: 4412 byte(s)
Log Message:
project almost done
Line File contents
1 <?php
2 /*
3 * Script: DataTables server-side script for PHP and MySQL
4 * Copyright: 2010 - Allan Jardine
5 * License: GPL v2 or BSD (3-point)
6 */
7
8 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9 * Easy set variables
10 */
11
12 /* Array of database columns which should be read and sent back to DataTables. Use a space where
13 * you want to insert a non-database field (for example a counter or static image)
14 */
15 $aColumns = array( 'vaccine_id', 'serotype_id', 'accession_number', 'patient_name');
16 /* Indexed column (used for fast and accurate table cardinality) */
17 $sIndexColumn = "serotype_id";
18
19 /* DB table to use */
20 $sTable = "attenuated_vaccine";
21
22 include "config.php";
23
24
25 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
26 * If you just want to use the basic configuration for DataTables with PHP server-side, there is
27 * no need to edit below this line
28 */
29
30 /*
31 * MySQL connection
32 */
33 $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
34 die( 'Could not open connection to server' );
35
36 mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
37 die( 'Could not select database '. $gaSql['db'] );
38
39
40 /*
41 * Paging
42 */
43 $sLimit = "";
44 if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
45 {
46 $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
47 mysql_real_escape_string( $_GET['iDisplayLength'] );
48 }
49
50
51 /*
52 * Ordering
53 */
54 if ( isset( $_GET['iSortCol_0'] ) )
55 {
56 $sOrder = "ORDER BY ";
57 for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
58 {
59 if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
60 {
61 $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
62 ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
63 }
64 }
65
66 $sOrder = substr_replace( $sOrder, "", -2 );
67 if ( $sOrder == "ORDER BY" )
68 {
69 $sOrder = "";
70 }
71 }
72
73
74 /*
75 * Filtering
76 * NOTE this does not match the built-in DataTables filtering which does it
77 * word by word on any field. It's possible to do here, but concerned about efficiency
78 * on very large tables, and MySQL's regex functionality is very limited
79 */
80 $sWhere = "";
81 if ( $_GET['sSearch'] != "" )
82 {
83 $sWhere = "WHERE (";
84 for ( $i=0 ; $i<count($aColumns) ; $i++ )
85 {
86 $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
87 }
88 $sWhere = substr_replace( $sWhere, "", -3 );
89 $sWhere .= ')';
90 }
91
92 /* Individual column filtering */
93 for ( $i=0 ; $i<count($aColumns) ; $i++ )
94 {
95 if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
96 {
97 if ( $sWhere == "" )
98 {
99 $sWhere = "WHERE ";
100 }
101 else
102 {
103 $sWhere .= " AND ";
104 }
105 $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
106 }
107 }
108
109
110 /*
111 * SQL queries
112 * Get data to display
113 */
114 $sQuery = "
115 SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
116 FROM $sTable
117 $sWhere
118 $sOrder
119 $sLimit
120 ";
121 $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
122
123 /* Data set length after filtering */
124 $sQuery = "
125 SELECT FOUND_ROWS()
126 ";
127 $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
128 $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
129 $iFilteredTotal = $aResultFilterTotal[0];
130
131 /* Total data set length */
132 $sQuery = "
133 SELECT COUNT(".$sIndexColumn.")
134 FROM $sTable
135 ";
136 $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
137 $aResultTotal = mysql_fetch_array($rResultTotal);
138 $iTotal = $aResultTotal[0];
139
140
141 /*
142 * Output
143 */
144 $output = array(
145 "sEcho" => intval($_GET['sEcho']),
146 "iTotalRecords" => $iTotal,
147 "iTotalDisplayRecords" => $iFilteredTotal,
148 "aaData" => array()
149 );
150
151 $row_id = '';
152 while ( $aRow = mysql_fetch_array( $rResult ) )
153 {
154 $row = array();
155 for ( $i=0 ; $i<count($aColumns) ; $i++ )
156 {
157 if($aColumns[$i] == 'accession_number'){
158 $value = $aRow[ $aColumns[$i] ];
159 $row[] = "<a target=\"_blank\" href=\"http://www.ncbi.nlm.nih.gov/nuccore/$value\">$value</a>";
160 }
161 else if( $aColumns[$i] != ' ' )
162 {
163 /* General output */
164 $value = $aRow[ $aColumns[$i] ];
165 $row[] = $value;
166 }
167 }
168 $output['aaData'][] = $row;
169 }
170
171 echo json_encode( $output );
172 ?>

Properties

Name Value
svn:eol-style native