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
| <?php
/*
** Script de visualisation des données en fonction d'une certaine reqûete !
*/
define('DB_HOST', 'localhost');
define('DB_USER', 'dbuser');
define('DB_PASS', 'dbpassword');
define('DB_NAME', 'dbname');
// Connexion à la base !
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
//creating a query
$stmt = $conn->prepare("select llx_socpeople.rowid, llx_socpeople.civility, llx_socpeople.lastname, llx_socpeople.firstname, llx_socpeople.address, llx_socpeople.zip, llx_socpeople.town, llx_socpeople.fk_pays, llx_socpeople.phone, llx_socpeople.no_email,llx_socpeople.note_public, llx_socpeople_extrafields.site, llx_socpeople_extrafields.latitude, llx_socpeople_extrafields.longitude from llx_socpeople, llx_socpeople_extrafields, llx_categorie_contact where (llx_socpeople.rowid = llx_categorie_contact.fk_socpeople) and (llx_socpeople.rowid = llx_socpeople_extrafields.fk_object) and (llx_categorie_contact.fk_categorie=1);");
//executing the query
$stmt->execute();
//binding results to the query
$stmt->bind_result($rowid, $civility, $lastname, $firstname, $address, $zip, $town, $fk_pays, $phone, $no_email, $note_public, $site, $latitude, $longitude);
$products = array();
$i=0;
//traversing through all the result
while($stmt->fetch()){
$temp = array();
$temp['rowid'] = $rowid;
$temp['civility'] = $civility;
$temp['lastname'] = $lastname;
$temp['firstname'] = $firstname;
$temp['address'] = $address;
$temp['zip'] = $zip;
$temp['town'] = $town;
$temp['fk_pays'] = $fk_pays;
$temp['phone'] = $phone;
$temp['no_email'] = $no_email;
$temp['note_public'] = $note_public;
$temp['site'] = $site;
$temp['latitude'] = $latitude;
$temp['longitude'] = $longitude;
array_push($products, $temp);
}
$sortie = json_encode($products);
//echo json_encode( $products );
$error = json_last_error();
echo "Erreur json : $error";
//print_r(array_values($products));
?> |
Partager