Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can you please suggest me why the value of i increase by own when i am fetching data from data base . Actually i am fetching data from table in phone gap .But along with i also count the number of elements in another table .while fetching the value of i increase by own and getting an error..Item index is out of range.
C#
function getallTableData(tx) {

   tx.executeSql('SELECT * FROM CaseTable', [], querySuccess, errorCB);
}

    function querySuccess(tx, result) {

        var len = result.rows.length;
        var countDoument=0
        $('#folderData').empty();
        for (var i = 0; i < len; i++) {

             alert(i)  // here value is i =0

             test1=result.rows.item(i).CaseName;



    Test1(test1,function(result_count){
    countDoument=result_count;   // here it count value
    alert(result_count+"result_count")  //alert is correct count value
    alert(i+"i"); //here i comes 1 why ? it should be 0

    $('#folderData').append(
                    '<li class="caseRowClick" id="' + result.rows.item(i).id + '" data-rel="popup" data-position-to="window">' + '<a href="#">' + '<img src="img/Blue-Folder.png">' + '<h2>' + result.rows.item(i).CaseName +countDoument+'</h2>' + '<p>' + result.rows.item(i).TextArea + '</p>' + '<p>' + result.rows.item(i).CaseDate + '</p>' + '</a>' +
                     '<span class="ctrl togg"><fieldset data-role="controlgroup" data-type="horizontal" data-mini="true" ><button class="edit button_design">Edit</button><button class="del button_design">Delete</button></fieldset><span>'+'</li>'
                    );

        });

       $('#folderData').listview('refresh');




    }


    }

    function Test1(test, callBack){
        var x;
        db.transaction(function (tx) {
                $yoursql = 'SELECT * FROM  "'+test+'" ';
                tx.executeSql($yoursql, [], function (tx, results) {
                    x = results.rows.length  + "TableName" + test;
                    callBack(x);
                });
        });

    }

Check my comments also..!!
Posted

1 solution

VB
for (var i = 0; i < len; i++)


In that For Loop you are incrementing i by 1 so it's getting incremented...

try using
VB
for (var i = 0; i < len-1 ; i++)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900