Commit e1d98ab8 authored by Raulin's avatar Raulin

journal (read create)

parent e6108cfa
......@@ -14,13 +14,13 @@ require_once("template.php");
// }
// else{ //sinon il s'agit d'un ajout
if(isset($_POST["date"]) && isset($_POST["quantite"]) && isset($_POST["select_aliment"])){
$idprovisoire=1;
$id=$_SESSION['id'];
$a='SELECT `id_aliment` FROM `aliments` WHERE `aliment` ="'.$_POST["select_aliment"].'"';
$b = $mysqli->query($a);
$c=$b->fetch_all();
$idaliment= $c[0][0];
$requete="INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '" .$_POST['date'] . "', '" .$idprovisoire . "', '" .$idaliment . "', '" . $_POST['quantite'] . "')";
$requete="INSERT INTO `journal` (`date`,`id`, `id_aliment`,`quantite`) VALUES ( '" .$_POST['date'] . "', '" .$id . "', '" .$idaliment . "', '" . $_POST['quantite'] . "')";
$mysqli->query($requete);
$msg="L'élément a bien été ajouté au journal";
} else{
......
<?php
require_once("template.php");
$requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']."AND `journal`.`id` = ".$_POST['varIdUser'];
$id=$_SESSION['id'];
$requete="DELETE FROM `journal` WHERE `journal`.`id_aliment` = ".$_POST['varIdAliment']."AND `journal`.`id` = ".$id;
$result = $mysqli->query($requete);
<?php
require_once("template.php");
$requete="SELECT `date`, `aliment`,`type`,`calories`,`quantite`, `journal`.`id_aliment`,`journal`.`id` FROM `journal` JOIN `aliments` ON `journal`.`id_aliment`=`aliments`.`id_aliment`";
$id=$_SESSION['id'];
$requete="SELECT `date`, `aliment`,`type`,`calories`,`quantite`, `journal`.`id_aliment`,`journal`.`id` FROM `journal` JOIN `aliments` ON `journal`.`id_aliment`=`aliments`.`id_aliment` WHERE `journal`.`id`=".$id;
$result = $mysqli->query($requete);
$journal=$result->fetch_all();
......
<?php
session_start();
header('Content-Type: application/json'); //pour que le navigateur l'affiche dans le format json
include('bdd.php');
......
......@@ -9,19 +9,21 @@
$(document).ready(function() {
$('#table_aliments').DataTable();
resetForm();
} );
function resetForm() {
document.getElementById("submit_button").value="Ajouter";
document.getElementById("quantite").value = "";
document.getElementById("date").value = "";
document.getElementById("mode").value = "";
// document.getElementById("mode").value = "";
};
};
</script>
<script type="text/javascript">
$(document).ready( function() {
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_aliments.php',
function(json){
......@@ -39,7 +41,7 @@
});
$(document).ready( function() {
// getId();
$.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/read_journal.php',
function(json){
table = $('#tbody_journal');
......@@ -48,13 +50,26 @@
// cf. https://api.jquery.com/jQuery.getJSON/
$.each( json, function( key, val ) {
table.append('<tr><td>'+val[0]+'</td><td>'+val[1]+'</td><td>'+val[2]+'</td><td>'+val[3]+'</td><td>'+val[4]+'</td><td><button '+
table.append('<tr><td>'+val[0]+'</td><td>'+val[1]+'</td><td>'+val[2]+'</td><td>'+val[3]*val[4]+'</td><td>'+val[4]+'</td><td><button '+
'onclick="onEdit(\''+val[0]+'\',\''+val[1]+'\',\''+val[4]+'\')">Modifier</button></td><td><button '+
'onclick="onDelete('+val[5]+','+val[6]+')">Supprimer</button></td></tr>');
});
}
);
});
// function getId(){
// var varlogin= sessionStorage.getItem('para');
// $.ajax({
// url: 'api/read_journal.php',
// type: 'POST',
// data: {'varlogin' : varlogin},
// success: function(varlogin){
// alert(varlogin);// reponse contient l'affichage du fichier PHP (soit echo)
// }
// })
// };
function onEdit(date, aliment, quantite) {
document.getElementById("date").value = date;
......@@ -64,7 +79,7 @@
document.getElementById("submit_button").value='Modifier';
};
function onDelete(varIdUser, id_user){
function onDelete(id_aliment, id_user){
var varIdAliment= id_aliment;
var varIdUser= id_user;
$.ajax({
......@@ -133,7 +148,7 @@
<input type="number" id="quantite" name="quantite" required>
</div>
<div>
<input type="text" id="mode" name="mode" style="display : none" >
<input type="text" id="mdifier" name="modifier" >
</div>
<div class="form-action-buttons">
......
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