\n";
}
echo "//Création du tableau JavaScript\n";
echo $NomTableauJavaScript."=new Array();\n";
echo "\n";
//Création du tableau PHP qui va contenir les noms des champs de la requêtes SQL
while ($CompteurChamp < mysql_num_fields($Resultat)) {
$meta = mysql_fetch_field($Resultat, $CompteurChamp);
if (!$meta) {
//echo "No information available \n";
}
//echo "$meta->name ";
$ChampsDeLaRequeteSQL[$CompteurChamp] = $meta->name;
$CompteurChamp++;
}
//Création des différents champs dans le tableau en JavaScript
echo "//Création des différents champs du tableau JavaScript\n";
$count = count($ChampsDeLaRequeteSQL);
for ($CompteurChampsDeLaRequete = 0; $CompteurChampsDeLaRequete < $count; $CompteurChampsDeLaRequete++) {
//echo $ChampsDeLaRequeteSQL[$CompteurChampsDeLaRequete]."\n";
echo $NomTableauJavaScript."['".$ChampsDeLaRequeteSQL[$CompteurChampsDeLaRequete]."']=new Array();\n";
}
echo "\n";
mysql_data_seek($Resultat, 0); //On revient au début de l'enregistrement
$CompteurResultats = 1; //Initialisation
echo "//Copie des valeurs dans les différents champs du tableau JavaScript\n";
while ($MaLigne=mysql_fetch_array($Resultat, MYSQL_ASSOC)){
for ($CompteurChampsDeLaRequete = 0; $CompteurChampsDeLaRequete < $count; $CompteurChampsDeLaRequete++) {
$line = $MaLigne[$ChampsDeLaRequeteSQL[$CompteurChampsDeLaRequete]];
if (mb_detect_encoding($line, 'UTF-8', true) === false) {$line = utf8_encode($line);}
//htmlspecialchars avec le paramètre ENT_COMPAT est essentiel. En effet on affecte une valeur, par exemple Ma_valeur, au tableau javascript ainsi :
//MonTableauJava['macle'] = "Ma_valeur"; Mais si Ma_valeur contient un double quote alors cela fait bugger le code avec une affectation du style
//MonTableauJava['macle'] = "Ma_"valeur"";
$line = htmlspecialchars ($line, ENT_COMPAT, 'UTF-8');
echo $NomTableauJavaScript."['".$ChampsDeLaRequeteSQL[$CompteurChampsDeLaRequete]."'][".$CompteurResultats."] = \"".$line."\";\n";
}
$CompteurResultats++;
}
if ($CreerBalisesJavaScript == 1){
echo "\n";
}
/* Types de méta possibles :
blob: $meta->blob
max_length: $meta->max_length
multiple_key: $meta->multiple_key
name: $meta->name
not_null: $meta->not_null
numeric: $meta->numeric
primary_key: $meta->primary_key
table: $meta->table
type: $meta->type
unique_key: $meta->unique_key
unsigned: $meta->unsigned
zerofill: $meta->zerofill
*/
}
echo "\n";
?>