-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtbReserv.php
68 lines (44 loc) · 1.67 KB
/
tbReserv.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*In this section there are a table who show all the data charge from the data base of the table tbReserv*/
require 'db/db.php';
if($_POST){
/*--------------date format transform----------*/
$restCapacity=32;
$fecha=date("Y-m-d",strtotime($_POST["H"] ));
$hour=$_POST["D"];
$dbTables= $database->query("select ".$restCapacity."-count(peopleAmount) mesas from tbreservations where reservationHour='".$hour."' and
tbreservations.date='".$fecha."';")->fetchAll(PDO::FETCH_ASSOC);
$array=array();
$size=count($dbTables);
/*--for for saving the data from database*/
for($index=0;$index<$size;$index++){
$array[$index]=$dbTables[$index]["mesas"];
}
if($array[0]>4){
$lista=["1 Mesa","2 Mesas","3 Mesas","4 Mesas"];
createJSON($lista);
}
if($array[0]<4 and $array[0]>2){
$lista=["1 Mesa","2 Mesas","3 Mesas"];
createJSON($lista);
}
if($array[0]<3 and $array[0]>1){
$lista=["1 Mesa","2 Mesas"];
createJSON($lista);
}
if($array[0]<2){
$lista=["1 Mesa"];
createJSON($lista);
}
}//end of if for method POST
/*------------this is a method that make the list of the hours to reserv-------------------*/
function createJSON($data){
$len = count($data);
for($i=0; $i<$len; $i++) {
$item = new stdClass;
$item->name = $data[$i];
$items[] = $item;
}
echo json_encode($items);
}
?>