1

Am trying to display query contents in HTMl using following jquery

    $tableSearch = $('#table-search');
    $tableSearch.html('<tr><th>Name</th><tr><th>Hours</tr></th><tr><th>MB</th></tr>'); 
    result.forEach(function(row) {
     $('#table-search tr').append('<td>'+ row.Date +'</td>'+'<td>'+ row.Hours+'</td>'+'<td>'+ row.MB+'</td>'); 
        });

But it gives the result like below

enter image description here

Actually I want the result like this enter image description here

How to format those values like above.

5
  • 1
    Please click edit, then [<>] snippet editor and post a minimal reproducible example with relevant input Commented Feb 19, 2020 at 10:02
  • Also there is no way <tr><th>Name</th><tr><th>Hours</tr></th><tr><th>MB</th></tr> will give you a vertical header on its own Commented Feb 19, 2020 at 10:04
  • Lastly there is no PHP issue here unless you want to do the code on the server Commented Feb 19, 2020 at 10:05
  • How to get this values in Php @mplungjan Commented Feb 19, 2020 at 10:06
  • they come from somewhere. The logic in PHP would be the same as in JS. So you need to make a choice. Commented Feb 19, 2020 at 10:13

1 Answer 1

1

First, you need to define class or id on <tr> tag of table header row, And then append the data as class/id wise row.

$tableSearch = $('#table-search');
    $tableSearch.html('<tr class="tr1"><th>Name</th><tr class="tr2"><th>Hours</tr></th><tr class="tr3"><th>MB</th></tr>'); 
    result.forEach(function(row) {
    $('#table-search .tr1').append('<td>'+ row.Date +'</td>');
     $('#table-search .tr2').append('<td>'+ row.Hours+'</td>');
     $('#table-search .tr3').append('<td>'+ row.MB+'</td>');
   });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.