Commit ede81403 authored by Raulin's avatar Raulin

affichage aliments

parent 0da7988e
<?php
require_once("template.php");
$requete="SELECT * FROM ALIMENTS";
$result = $mysqli->query($requete);
$aliments=$result->fetch_all();
$rep=reponse_json($aliments);
echo $rep['result'][0][1];
// echo json_encode($aliments);
// echo json_encode($aliments[0][1]);
// reponse_json($success, $data);
\ No newline at end of file
<?php
require_once("template.php");
if(isset($_POST["aliment"]) && isset($_POST["cat"])){
$requete="INSERT INTO `ALIMENTS` (`ID_ALIMENT`,`NAME_ALIMENT`, `TYPE_ALIMENT`) VALUES (NULL, '" .$_POST['aliment'] . "', '" . $_POST['cat'] . "')";
$mysqli->query($requete);
$msg="L'aliment a bien été ajouté";
} else{
$msg="Il manque des informations";
}
echo $msg;
<?php
try{
DEFINE('DB_USERNAME','charlotte.raulin');
DEFINE('DB_PASSWORD','MIZWqEaY');
DEFINE('DB_HOST','127.0.0.1');
DEFINE('DB_DATABASE','charlotte_raulin');
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$retour["success"]=true;
} catch(Exception $e){
$retour["success"]=false;
};
?>
\ No newline at end of file
<?php
header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json
include('bdd.php');
function reponse_json($data){
$array['result']=$data;
echo json_encode($data);
}
// echo json_encode($aliments);
// $retour = array();
// $retour["aliments"]= array();
// $retour["aliments"][0]["id"] = 1;
// $retour["aliments"][0]["name"] = "Pomme";
// $retour["aliments"][0]["type"] = "Fruit";
// $retour["aliments"][1]["id"] = 2;
// $retour["aliments"][1]["name"] = "Poire";
// $retour["aliments"][1]["type"] = "Fruit";
// `LOGIN`
\ No newline at end of file
This diff is collapsed.
<?php <?php
include("template.php"); require_once("template.php");
$requete="SELECT * FROM ALIMENTS"; $requete="SELECT * FROM ALIMENTS";
$result = $mysqli->query($requete); $result = $mysqli->query($requete);
$aliments=$result->fetch_all(); $aliments=$result->fetch_all();
json_encode($aliments); reponse_json($aliments);
// reponse_json($success, $data);
\ No newline at end of file
...@@ -2,14 +2,11 @@ ...@@ -2,14 +2,11 @@
header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json
include('bdd.php'); include('bdd.php');
// function reponse_json($success, $data, $msgErreur=NULL){ function reponse_json($data){
// $array['success']=$_success;
// $array['msg']=$msgErreur;
// $array['result']=$data;
// echo json_encode($msg,$data); echo json_encode($data);
// } }
......
<!-- <head>
<script type="text/javascript">
$(document).ready(function() {
Alert.alert("func");
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php',
function(json){
Alert.alert("get");
for (let i = 0; pas < 2; pas++){
Alert.alert("hey");
$('#test').append(json[i][1]+'<br>'+json[i][2]);
}
};
);
} );
</script>
</head>
<div id="test">hallo</div>
<script type="text/javascript">
function getAliments(){
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php',
function(json){
for (let i = 0; pas < 2; pas++){
alert(json[1][1]);
$('#test').append(json[i][1]+'<br>'+json[i][2]);
}
};
);
}
getAliments();
</script> -->
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment