Tu rajoutes juste le echo $sQuery dans le fichier chargementbdd.php. J'irai voir sur ton site pour voir ce que cela donne.
Version imprimable
Tu rajoutes juste le echo $sQuery dans le fichier chargementbdd.php. J'irai voir sur ton site pour voir ce que cela donne.
c'est fait !
Je ne peux pas tester mais essaye déjà de supprimer tous les `` présents dans le fichier chargementbdd.php. Puis encadrer le champ table par ``dans $aColumns = array.
Je te remercie pour le temps que tu passes maintenant avec moi !
Merci de vouloir m'aider !
Voilà, j'essaye autre chose :
J'ai modifié (en fin de chargementbdd.php" comme suit :
Par contre pour changer les " en simple ' dans la ligne 89Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 while ( $aRow = mysql_fetch_array( $rResult ) ) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( $aColumns[$i] == "version" ) { /* Special output formatting for 'version' column */ $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ]; } else if ( $aColumns[$i] != ' ' ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $row[9]= $aRow['table']; $output['aaData'][] = $row; }
du "changementbdd.php", cela n'est pas possible !
Cela t'aide pour voir plus !
J'ai rajouté dans chargementbdd.php, ceci :
.Code:$row[9]= $aRow['table'];
Malgré un contenu bien présent dans la bdd,
j'ai une colonne "vide" pour la colonne "table"
Je me rends compte que le fichier de traitement php est déjà conçu de façon à échapper les mots réservés (tel que "table"). Donc inutile de s'occuper de ce problème. Repars de ton code php d'origine, sachant que la variable $aColumns doit absolument se présenter ainsi (avec des simples quotes pour tous les champs):
Je pars du principe que tu n'as pas rien modifié d'autre dans le fichier php fourni avec datatablesCode:
1
2 $aColumns = array( 'item_id', 'cut', 'carat', 'cut_grade', 'color', 'clarity', 'polish', 'symmetry', 'depth', 'table', 'fluo_intensity', 'price_per_carat', 'culet_size', 'total_price' );
Par ailleurs, est-tu sûr d'avoir ajouté le "echo $sQuery" dans le fichier chargementbdd.php car rien ne s'affiche dans firebug lorsque je vais sur ton site.
Voilà, j'ai remis tout entre simples quotes.
J'ai rajouté ton echo (... en ton absence, j'ai testé d'autres pistes...)
J'ai remis le "changementbdd.php", comme à l'origine de dataTables,
avec juste la partie supérieure modifiée pour les champs et connexion bdd !
Et puis bizarre, avec la ligne rajoutée en fin de "chargementbdd.php",
,Code:
1
2 $row[9]= $aRow['table'];
j'obtiens une colonne "vide" !!!
Bizarre !
J'imagine que tu testes en localhost ? Sur ton site en ligne, je ne vois pas ta requête. Peux-tu mettre en ligne ton dernier fichier php ?
Non, vu la complexité du truc, cela fait belle lurette que je teste directement sur le site !
Pour le fun, j'ai refait un upload des fichiers !
Pour rappel, je travaille avec la page "www.celinni.com/creaprint/simple00.php" et "js/dt/chargementbdd.php"!
Tu as trouvé la requete ?
En fait je regardais la page du lien que tu avais donné sur ton 1er post...
As-tu essayé de modifier la ligne ainsi :
Code:
1
2 $aColumns = array( 'item_id', 'cut', 'carat', 'cut_grade', 'color', 'clarity', 'polish', 'symmetry', 'depth', '`table`', 'fluo_intensity', 'price_per_carat', 'culet_size', 'total_price' );
Et pense à supprimer le echo$sQuery;
Tiens, tiens...
Toi aussi, tu obtiens une colonne "vide" !
c'est comme si tu avais mis ma ligne, en fin de "chargementbdd.php", comme dit il y a qq messages plus hauts :
Et cependant, je viens de revérifier, ce champ a bien un evaleur pour bon nombre de références !Code:$row[9]= $aRow['table'];
Apparemment, le problème serait plutôt avec JSON...
Mais là, je n'y connais rien !
Peux-tu m'aider ?
J'ai aussi tenté :
en fin de "chargementbdd.php"Code:
1
2
3 $table="table"; $row[9]=$aRow['$table'];
Pourrais-tu poster le code de la dernière version de ton fichier chargementbdd.php ?
Aussitôt dit, aussitôt fait :
Code:
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 <?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( 'item_id', 'cut', 'carat', 'cut_grade', 'color', 'clarity', 'polish', 'symmetry', 'depth', 'table', 'fluo_intensity', 'price_per_carat', 'culet_size', 'total_price'); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "item_id"; /* DB table to use */ $sTable = "diamant_data"; /* Database connection information */ $gaSql['user'] = "x"; $gaSql['password'] = "y"; $gaSql['db'] = "z"; $gaSql['server'] = "u"; /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */ /* include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" ); */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * If you just want to use the basic configuration for DataTables with PHP server-side, there is * no need to edit below this line */ /* * MySQL connection */ $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or die( 'Could not open connection to server' ); mysql_select_db( $gaSql['db'], $gaSql['link'] ) or die( 'Could not select database '. $gaSql['db'] ); /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ". mysql_real_escape_string( $_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] ) ]." ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", "; } } $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) ; $i++ ) { $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) ; $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])."%' "; } } /* * SQL queries * Get data to display */ $sQuery = " SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))." FROM $sTable $sWhere $sOrder $sLimit "; $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; /* Total data set length */ $sQuery = " SELECT COUNT(".$sIndexColumn.") FROM $sTable "; $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; /* * Output */ $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); while ( $aRow = mysql_fetch_array( $rResult ) ) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( $aColumns[$i] == "version" ) { /* Special output formatting for 'version' column */ $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ]; } else if ( $aColumns[$i] != ' ' ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $output['aaData'][] = $row; } echo json_encode( $output ); ?>
Edite ton message car tu as laissé tes identifiants. Réessaie avec ce code qui réintègre l'échappement des mots réservés :
Code:
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 <?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( 'item_id', 'cut', 'carat', 'cut_grade', 'color', 'clarity', 'polish', 'symmetry', 'depth', 'table', 'fluo_intensity', 'price_per_carat', 'culet_size', 'total_price'); /* Indexed column (used for fast and accurate table cardinality) */ $sIndexColumn = "item_id"; /* DB table to use */ $sTable = "diamant_data"; /* Database connection information */ $gaSql['user'] = "****"; $gaSql['password'] = "****"; $gaSql['db'] = "****"; $gaSql['server'] = "****"; /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */ /* include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" ); */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * If you just want to use the basic configuration for DataTables with PHP server-side, there is * no need to edit below this line */ /* * MySQL connection */ $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or die( 'Could not open connection to server' ); mysql_select_db( $gaSql['db'], $gaSql['link'] ) or die( 'Could not select database '. $gaSql['db'] ); mysql_set_charset( 'utf8' ); /* * Paging */ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". intval( $_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) ; $i++ ) { $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) ; $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])."%' "; } } /* * SQL queries * Get data to display */ $sQuery = " SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."` FROM $sTable $sWhere $sOrder $sLimit "; $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); /* Data set length after filtering */ $sQuery = " SELECT FOUND_ROWS() "; $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal); $iFilteredTotal = $aResultFilterTotal[0]; /* Total data set length */ $sQuery = " SELECT COUNT(`".$sIndexColumn."`) FROM $sTable "; $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error()); $aResultTotal = mysql_fetch_array($rResultTotal); $iTotal = $aResultTotal[0]; /* * Output */ $output = array( "sEcho" => intval($_GET['sEcho']), "iTotalRecords" => $iTotal, "iTotalDisplayRecords" => $iFilteredTotal, "aaData" => array() ); while ( $aRow = mysql_fetch_array( $rResult ) ) { $row = array(); for ( $i=0 ; $i<count($aColumns) ; $i++ ) { if ( $aColumns[$i] == "version" ) { /* Special output formatting for 'version' column */ $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ]; } else if ( $aColumns[$i] != ' ' ) { /* General output */ $row[] = $aRow[ $aColumns[$i] ]; } } $output['aaData'][] = $row; } echo json_encode( $output ); ?>
Merci. Tu es génial !
Cela fonctionne !!!
Qu'as-tu rajouté ?
Juste
?Code:mysql_set_charset( 'utf8' );
Je poursuis alors dans ma quête toute initiale.
J'ai rajouté 4 champs à calculer pour chaque ligne du dataTables !
(d'abord une casse à cocher pour "a comparer", ensuite 2 champs à calculer en fonction des champs de la référence lue, et enfin un bouton... 1+2+1=4 !!!)
Pour ce faire, je les insère dans "chargementbdd.php",
en insérant des ' ' aux places requises !
Et là, reproblème JSON, avant même la calculation !
Peux-tu encore m'aider ?
Je sais que j'abuse !
J' (pardon, tu) avance(s) bien sur ma dataTables !
Merci à toi !
Voici le nouveau détail de la table :
Code:
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 <table cellpadding="0" cellspacing="0" border="0" class="display" id="example"> <thead> <tr> // 1 colonne rajoutée ici <th align='center' style='width:25px;'></th> // <th align='left'> idreference</th> <th align='left'> forme</th> <th align='right' style='width:30px;'> carat</th> <th align='left'> taille</th> <th align='center' style='width:45px;'> couleur</th> <th align='center' style='width:45px;'> pureté</th> <th align='center' style='width:45px;'> poli</th> <th align='center' style='width:45px;'> sym</th> <th align='center' style='width:45px;'> prof</th> <th align='center' style='width:45px;'> table</th> <th align='center' style='width:45px;'> fluo</th> <th align='right' style='width:45px;'> prix/ct</th> <th align='center' style='width:45px;'> colette</th> // 2 colonnes rajoutées ici <th align='right' style='width:45px;'> Lg/lg</th> <th align='right'> délai</th> // <th align='right'> prix</th> // 1 colonne rajoutée ici <th> détail</th> // </tr> </thead> <tbody> </tbody> </table>
Pour le fichier php, tu avais laissé des modifications par rapport au fichier fourni avec datatable (les fameux ` `).
Concernant ton autre question, je te conseille d'abord de mettre en résolu la 1ere question puis d'ouvrir un nouveau sujet. Par ailleurs, pense à te référer à firebug car, dans le cas présent, il indique l’erreur suivante (voir fichier joint) :
Code:
1
2 Unknown column ' ' in 'field list'
Merci.
Grand merci.