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)); } }); 

  • And what does “group by days” mean, here we have two entries in one day with different times, what should be with the content when outputting “grouped” data? - Mike
  • Not, let's say div 25 is the number - in ul-li all notes of this date, for 26 div - all notes for that day and so on. So that the days could be distinguished. - Vlad
  • then add order by date to 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
  • Request added, but with a cycle is not entirely clear. - Vlad
  • Doesn't work at all? It looks all right, I really have never seen working with the database on JS, so I can’t be sure about the correctness of this particular part. There is only one remark, for the last date you need to print an array after the cycle if it is not empty - Mike

0