0

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 = '';


        }

    });
});
1
  • Think about how to debug it. For example, try print_r(results); to see what you get, if anything. Commented Mar 3, 2020 at 5:32

2 Answers 2

1

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

results.rows.item[i].Firstname  

NOT

results.rows.item(i).Firstname
Sign up to request clarification or add additional context in comments.

11 Comments

if im using the [] then it will nor recognize the Firstname column
it giving me en error but is said "cannot read property 'Firstname' of undefined"
@YuvalBarzilai, just your result, do console.log(JSON.strigify(result));
im not using JSON, havent even imported anything
you dont have to import anything, after function (tx, results) { console.log(JSON.strigify(result)) to check if the results are coming after your query
|
0

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!!

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.