3

I have problems with my application that is when it will display the data from the database in the form of a data table that happen to two sideways instead of down

main.js

$(document).ready(function(){
var sql = ign.sql();
var driver = sql.driver("sqlite","peserta.sqlite");
var qry = sql.query("select * from data");

if(driver){
    //$(".json").html(JSON.stringify(qry));
    var query = qry;
    var html = "";

    $("p").html("Status Database Connection : "+query.status);
    if(query.status){

         $.each(query.content,function(data){
            html += "<td>"+this.no+"</td>";
            html += "<td>"+this.nama+"</td>";
            html += "<td>"+this.alamat+"</td>";
        });
    }

    $(".data").html(html);
}

});

this HTML

<!doctype html>

<p></p>
<!--
<h2>JSON Data</h2>
<div class="json"></div><hr> -->
<table>
<tr>
<td>No</td>
<td>Nama</td>
<td>Alamat</td>
</tr>
<tr class="data">
</tr>
</table>

1
  • wait this has nothing to do with your question but what linux distro is that?
    – washcloth
    Commented Nov 15, 2014 at 13:00

2 Answers 2

0

You must use the tags (table row) around your rows. Something like this should work:

$.each(query.content,function(data){
        html += "<tr>";
        html += "<td>"+this.no+"</td>";
        html += "<td>"+this.nama+"</td>";
        html += "<td>"+this.alamat+"</td>";
        html += "</tr>";
    });
3
  • thanks for the answer , but that's not what I mean , should the name of the column underneath the line no , row underneath the name of the column nama and so on . Commented Nov 15, 2014 at 13:15
  • @HaviedzMiftah, ah ok, I understand. That's a bit more complicated, since html doesn't directly allow for "horizontal tables". But you could do it by using this structure, though then you have to use several loops, one for numbers, one for name and one for alamat to generate each row. Commented Nov 15, 2014 at 14:16
  • but I do not understand the existing code between the script tags Commented Nov 17, 2014 at 4:59
0

In your html, replace

<tr class="data">

with

<tbody class="data">

and in your jQuery, do what @thorsten has suggested.

Also, you might have to replace the <td> tags in your static html to <th>, to make them headings and force browsers to render it as .

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.