1
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:
Since the grid created by this script represents the available places in a room, you needed to add a function for when to press the "search" button (for example between the dates 20-01-2017 and 27-01-2017 ILLUSTRATED BELOW) this one fills the squares with the colors according to the status of each place.
- red to purchased place
 - yellow for private seat
 - no color for available place
 
These reserve "status" would be returned from a php function:
tbl_reservations (MYSQL)
- id
 - name
 - phone
 - address
 - city
 - room (int)
 - place (int)
 - start_date (date)
 - end_date (date)
 - status (int) 0 or 1 or 2
 
php function - ANYTHING OF THIS KIND:
$sql = SELECT * FROM tbl_reservas WHERE (reserva esteja entre a data indicada ps: ainda tenho de pensar como vou fazer o algoritmo")
return query($sql)
My question is how can I change the script above written to do what the illustration shows ?


Good afternoon Bernardo. Your question is very wide. But I believe that a very simple solution would be to modify this script to better meet your requirements and to each reservation, wait or availability you change the database data through a request
ajax.– Andrew Ribeiro
I edited the question to not seem broad.
– Bernardo Ascensão
Really need to create the blocks using
javascript? I have seen for some time a function that interpreted the return of a requestAJAXable to perform functions via.post()/.get()/.ajax(). However it is not a good practice, but it would work– Leonardo Rodrigues
What would be the best practice to develop this project ?
– Bernardo Ascensão
The best way would be to create it via html+php, ai could request it with
jQueryvia.load(). However, it depends on how you use it and how you need it– Leonardo Rodrigues
I edited the topic to show the purpose of the script.
– Bernardo Ascensão