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
| <?php
/*
** Script de visualisation des données en fonction d'une certaine reqûete !
*/
define('DB_HOST', 'localhost');
define('DB_USER', 'user');
define('DB_PASS', 'password');
define('DB_NAME', 'database');
// Connexion à la base !
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
//Checking if any error occured while connecting
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$sql = "SELECT champs_1, champs_2, champs_3, champs_4, champs_5, champs_6, champs_7 FROM database";
$output = array();
$output["products"] = array();
// Parcours des résultats.
echo "début query.";
$e = mysqli_query($conn,"SELECT champs_1, champs_2, champs_3, champs_4, champs_5, champs_6, champs_7 FROM wpfd_5_gmp_markers");
echo "début while.";
$i=1;
while($row = mysqli_fetch_array($e)){
$ligne = array();
$ligne["champs_1"] = $row["champs_1"];
$ligne["champs_2"] = $row["champs_2"];
$ligne["champs_3"] = $row["champs_3"];
$ligne["champs_4"] = $row["champs_4"];
$ligne["champs_5"] = $row["champs_5"];
$ligne["champs_6"] = $row["champs_6"];
$ligne["champs_7"] = $row["champs_7"];
array_push($output["products"], $ligne);
echo "$i dans boucle while.";
$i++;
}
echo "print.";
//print($output);
echo json_encode($output); // encodage du tableau avec JSON
mysqli_close($conn);
?> |
Partager