Yuval Barzilai
Yuval Barzilai

Reputation: 1

Pulling data from SQLite, but data is undefined

I have a class project where I need to pull data from my SQLite DB and place it into <table>. But every time I reload the page I get this Table image and I was hoping for some help. I'm new to JavaScript and I need to finish this task in a few hours, I've tried to pull the data into an object and from the object into this line str += "<td>" + results.rows.item(i).Firstname + "</td>" and still it didn't work.

db.transaction(function (tx) {
    tx.executeSql('SELECT * FROM Customers_Table ', [], function (tx, results) {
        var len = results.rows.length, i;
        document.getElementById("tablea").innerHTML = '';
        var str = '';
        str += "<th>FirstName</th>";
        str += "<th>LastName</th>";
        str += "<th>Address</th>";
        str += "<th>City</th>";
        str += "<th>Email</th>";
        for (i = 0; i < len; i++) {
            str += "<tr>";
            str += "<td>" + results.rows.item(i).Firstname + "</td>";
            str += "<td>" + results.rows.item(i).Lastname + "</td>";
            str += "<td>" + results.rows.item(i).Address + "</td>";
            str += "<td>" + results.rows.item(i).City + "</td>";
            str += "<td>" + results.rows.item(i).Email + "</td>";
            str += "</tr>";

            document.getElementById("tablea").innerHTML += str;
            str = '';


        }

    });
});

Upvotes: 0

Views: 298

Answers (2)

Yuval Barzilai
Yuval Barzilai

Reputation: 1

Finally figured out the problem, the .Firstname and the rest didn't match the column names from the Db table, it was lowercase,look carefully at your code guys!!

Upvotes: 0

Sunil Lama
Sunil Lama

Reputation: 4539

Well, considering that you have data in results. It should be used as:

results.rows.item[i].Firstname  

NOT

results.rows.item(i).Firstname

Upvotes: 1

Related Questions