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
......@@ -9,6 +9,31 @@
$('#table_aliments').DataTable();
} );
</script>
<script type="text/javascript">
$(document).ready( function() {
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php',
function(json){
// console.log(json);
table = $('#tbody_aliment');
table.html('');
// cf. https://api.jquery.com/jQuery.getJSON/
$.each( json, function( key, val ) {
table.append('<tr><td>'+val[1]+'</td><td>'+val[2]+'</td></tr>');
});
}
);
// $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php',
// function(json){
// $.('#tbody_aliment').html('');
// for (let i = 1; i < json.lenght; i++){
// $('#tbody_aliment').append('<tr><td>'json[i][1]+'</td><td>'+json[i][2]+'</td></tr>');
// }
// };
// );
});
</script>
</head>
<section id="aliments_contenu" style="display : flex; flex-direction : row; ">
......@@ -23,354 +48,8 @@
<th>AjoutAuJournal</th>
</tr>
</thead>
<tbody>
<tr>
<td>Fromage</td>
<td>Laitage</td>
</tr>
<tr>
<td>Pâtes</td>
<td>Féculent</td>
</tr>
<tr>
<td>Haricots verts</td>
<td>Légumes</td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<tr>
<td>deja la</td>
<td>dela la </td>
</tr>
<tr>
<td>deja la </td>
<td>deja la </td>
</tr>
<!-- <tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr>
<tr>
<td>Row 1 Data 1</td>
<td>Row 1 Data 2</td>
</tr>
<tr>
<td>Row 2 Data 1</td>
<td>Row 2 Data 2</td>
</tr> -->
<tbody id="tbody_aliment"><tbody>
</tbody>
</table>
</div>
......@@ -398,7 +77,6 @@
</form>
</td>
</tr>
<!-- <script src="crud.js"></script> -->
</table>
</div>
</section>
\ No newline at end of file
<?php
include("template.php");
require_once("template.php");
$requete="SELECT * FROM ALIMENTS";
$result = $mysqli->query($requete);
$aliments=$result->fetch_all();
json_encode($aliments);
reponse_json($aliments);
// reponse_json($success, $data);
\ No newline at end of file
......@@ -2,14 +2,11 @@
header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json
include('bdd.php');
// function reponse_json($success, $data, $msgErreur=NULL){
// $array['success']=$_success;
// $array['msg']=$msgErreur;
// $array['result']=$data;
function reponse_json($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