function dbPopulateAttendanceTable(tableName, rows) {

	if(!tableName) {
		tableName = 'attendance';
	}

	var errors = [];
	var total = 0;
	var parsed = 0;

	for(var z in rows) {
		total += rows[z].rows.length;
	}

	for(var i in rows) {
		for(var x = 0; x < rows[i].rows.length; x++) {

			if(rows[i].rows[x].is_new != 1) {
				rows[i].rows[x].is_new = 0;
			}

			mysql.query('INSERT INTO `' + tableName + '` (student_id, event_id, is_new) VALUES ("' + rows[i].rows[x].student_id + '", "' + rows[i].table_name + '", "' + rows[i].rows[x].is_new + '")', function(err) {
				
				if(err) {
					errors.push(err);
				}

				if(++parsed >= total) {
					onPopulateAttendanceTable();
				}

			});
		}
	}

	function onPopulateAttendanceTable() {

		console.log('MYSQL', 'INFO', 'Successfully added', (total - errors.length), 'entries out of', total, 'to the `' + tableName + '` table.');

		if(errors.length) {
			console.log('MYSQL', 'LAST_ERROR', errors[errors.length - 1]);
		}
	}
	

}
/**
 * Perform an insert query on the attendance table
 * storing a reference to each student and event by ID
 *
 * @param rows Array of table rows
 */
Perform an insert query on the attendance table
storing a reference to each student and event by ID

@param rows Array of table rows
Perform an insert query on the attendance table storing a reference to each student and event by ID @param rows Array of table rows
function dbPopulateAttendanceTable(tableName, rows) {
	if(!tableName) {
		tableName = 'attendance';
	}
	var errors = [];
	var total = 0;
	var parsed = 0;
	for(var z in rows) {
		total += rows[z].rows.length;
	}
	for(var i in rows) {
		for(var x = 0; x < rows[i].rows.length; x++) {
			if(rows[i].rows[x].is_new != 1) {
				rows[i].rows[x].is_new = 0;
			}
			mysql.query('INSERT INTO `' + tableName + '` (student_id, event_id, is_new) VALUES ("' + rows[i].rows[x].student_id + '", "' + rows[i].table_name + '", "' + rows[i].rows[x].is_new + '")', function(err) {
				if(err) {
					errors.push(err);
				}
				if(++parsed >= total) {
					onPopulateAttendanceTable();
				}
			});
		}
	}
	function onPopulateAttendanceTable() {
		console.log('MYSQL', 'INFO', 'Successfully added', (total - errors.length), 'entries out of', total, 'to the `' + tableName + '` table.');
		if(errors.length) {
			console.log('MYSQL', 'LAST_ERROR', errors[errors.length - 1]);
		}
	}
}
function dbPopulateAttendanceTable ( tableName , rows ) { if ( ! tableName ) { tableName = 'attendance' ; } var errors = [ ] ; var total = 0 ; var parsed = 0 ; for ( var z in rows ) { total += rows [ z ] . rows . length ; } for ( var i in rows ) { for ( var x = 0 ; x < rows [ i ] . rows . length ; x ++ ) { if ( rows [ i ] . rows [ x ] . is_new != 1 ) { rows [ i ] . rows [ x ] . is_new = 0 ; } mysql . query ( 'INSERT INTO `' + tableName + '` (student_id, event_id, is_new) VALUES ("' + rows [ i ] . rows [ x ] . student_id + '", "' + rows [ i ] . table_name + '", "' + rows [ i ] . rows [ x ] . is_new + '")' , function ( err ) { if ( err ) { errors . push ( err ) ; } if ( ++ parsed >= total ) { onPopulateAttendanceTable ( ) ; } } ) ; } } function onPopulateAttendanceTable ( ) { console . log ( 'MYSQL' , 'INFO' , 'Successfully added' , ( total - errors . length ) , 'entries out of' , total , 'to the `' + tableName + '` table.' ) ; if ( errors . length ) { console . log ( 'MYSQL' , 'LAST_ERROR' , errors [ errors . length - 1 ] ) ; } } }
Perform an insert query on the attendance table
 storing a reference to each student and event by ID
Perform an insert query on the attendance table storing a reference to each student and event by ID