I do todo on JS and WebSQL. The structure of the table in the database: id | content | date (in mysql format - YYYY-MM-DD HH: MM: SS). The code is:
database.transaction(function(tx) { tx.executeSql("SELECT * FROM todo", [], function(tx, result) { for (var i = 0; i < result.rows.length; i++) { var id = result.rows.item(i).id; var content = result.rows.item(i).content; var bddate = result.rows.item(i).date; var date = new Date(bddate); var day = date.getDate(); // день // вывод } }); }); How to display not a whole list, but grouped by days?
UPD: Tried, but not working
tx.executeSql("SELECT * FROM todo ORDER BY DATE", [], function(tx, result) { // до тех пор пока есть данные var arrDay = []; var startDay = null; for (var i = 0; i < result.rows.length; i++) { var bddate = result.rows.item(i).date; var date = new Date(bddate); var day = date.getDate(); // день if (startDay == null) { startDay = day; } if (startDay != day) { console.log(arrDay); // вывод дневного массива arrDay.length = 0; startDay = day; } // добавляем в дневной массив arrDay.push(result.rows.item(i)); } });
order by dateto the request so that the records from the database in order of dates go on and then append the data to the div for the current day, remember the current day alternately and on the next cycle if the day has not changed further you print, if you change complete the current div and start the next - Mike