0

I am using Phonegap sqlite. I have one table in my database named "database" in which I have 3 columns.id,data,data_num I wanted to fetch all data from database and show it in html div.This is what I came up with:

Script:

<script>
      document.addEventListener("deviceready", onDeviceReady, false); 
      function refresh() {
        var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
       var name=document.forms["frm1"]["name"].value;
       var id=document.forms["frm1"]["id"].value;
       var sal=document.forms["frm1"]["sal"].value;
        db.transaction(function(tx) {
              tx.executeSql("SELECT data from test_table;", [], function(tx, res) {
                 var len = results.rows.length;
                 var databit;
                    if(len>0)
                    {
                        for (var i = 0; i < len; i++) 
                        {
                            databit=results.rows.item(0)['data']);
                        }
                    }
                    document.getElementById("data").innerHTML=databit;
              });
            });

      </script>

HTML

<input type="button" value="Refresh" onClick="return refresh()">
<div id="data"></div>

But it does'nt work as subjected.

NOTE:This is code snippet.Assume all undeclared variable as declared.

5
  • 1
    stackoverflow.com/questions/20698779/… hope this link will help Commented Jan 9, 2014 at 13:47
  • <div id="data"></div> quotes(") was missing for div id :) Commented Jan 9, 2014 at 13:49
  • " missing isn't the problem...I have tried it with " only.It was a typo while asking. :( Commented Jan 10, 2014 at 8:14
  • 1
    this link didnt helped you? Commented Jan 10, 2014 at 8:34
  • mark that as an answer than :) Commented Jan 10, 2014 at 14:28

0

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.