I am fetching multiple data from database with AJAX and PHP. After AJAX success I am grouping result data as shown in below images, in which I want a textarea
field per group.
I am trying with the following script
function getResult(id = null) {
if (id) {
$.ajax({
url: 'fetch.php',
type: 'post',
data: {id: id},
dataType: 'json',
success: function(response) {
var lastCategory = null;
response.result.forEach(function(element) {
console.log(element);
var category = element.category;
var names = element.name;
var Result = element.result;
var note = element.note;
if (lastCategory != category) {
$('table tr').length;
html = '<tr>';
html += '<td><p>'+category+'</p></td>';
html += '</tr>';
$('table').append(html);
lastCategory = category;
}
$('table tr').length;
html = '<tr>';
html += '<td><p>' + names + '</p></td>';
html += '<td><p>' + Result + '</p></td>';
html += '</tr>';
$('table').append(html);
$('table tr').length;
html = '<tr>';
html += '<td><textarea placeholder="textarea...">' + note + '</textarea></td>';
html += '</tr>';
$('table').append(html);
});
}
});
} else {
alert('error');
}
}
but it's giving this output:
This is the desired output: