Good
The script below serves to create a grid of numbered squares.
index.php
<script>
var lastClicked;
var grid = clickableGrid(5,22,function(el,row,col,i){
console.log("You clicked on element:",el);
console.log("You clicked on row:",row);
console.log("You clicked on col:",col);
console.log("You clicked on item #:",i);
el.className='clicked';
if (lastClicked) lastClicked.className='';
lastClicked = el;
});
document.body.appendChild(grid);
</script>
<script>
$('td').click(function(e) {
var cell = e.target;
var selected_number = $(e.target).text();
//alert(selected_number); (====> AQUI É O MEU PROBLEMA <====)
});
</script>
clickable-grid.css
.grid { margin:1em auto; border-collapse:collapse }
.grid td {
cursor:pointer;
width:30px; height:30px;
border:1px solid #ccc;
text-align:center;
font-family:sans-serif; font-size:13px
}
.grid td.clicked {
background-color:yellow;
font-weight:bold; color:red;
}
clickable-grid.js
function clickableGrid( rows, cols, callback ){
var i=0;
var grid = document.createElement('table');
grid.className = 'grid';
for (var r=0;r<rows;++r){
var tr = grid.appendChild(document.createElement('tr'));
for (var c=0;c<cols;++c){
var cell = tr.appendChild(document.createElement('td'));
cell.innerHTML = ++i;
cell.addEventListener('click',(function(el,r,c,i){
return function(){
callback(el,r,c,i);
}
})(cell,r,c,i),false);
}
}
return grid;
}
OUTPUT:
Giventhatthegridcreatedbythisscriptrepresentstheplacesavailableinaroom,youwouldneedtoaddafunctiontoitwhenyoupressthe"search" button (for example between the dates 20-01-2017 and 27-01-2017 ILLUSTRATED UNDER CONSTRUCTION ) this one fills the squares with the colors according to the status of each place.
- red for purchased place
- yellow for reserved place
- no color for available place
Thesereservationstatuseswouldbereturnedfromaphpfunction:
tbl_reserves(MYSQL)
- id
- name
- phone
- address
- city
- room(int)
- place(int)
- start_date(date)
- end_date(date)
- status(int)0or1or2
phpfunction-ANYTHINGOFTHISTYPE:
$sql=SELECT*FROMtbl_reservasWHERE(reservaestejaentreadataindicadaps:aindatenhodepensarcomovoufazeroalgoritmo")
return query($sql)
My question is how can I change the script above written to do what the illustration shows?