2013-06-29 1 views
1

을 작동하지 않습니다 :COUNT (*) 웹 SQL에서이 코드는 다음과 같다, 내가 emp 테이블의 레코드 수를 얻기 위해 다음 코드를 사용하고

var myDb = initDB(); 
    myDb.transaction(function(trans) { 
    var query = "SELECT COUNT(*) AS c from emp"; 
     trans.executeSql(query, [], function(trans, res) { 
      var count = res.rows[0].c; 
      console.log("--- After Count ---"+count); 
    }, errorHandler); }); 

The query is giving error : Uncaught TypeError: Cannot read property 'c' of undefined. 
How to solve this issue? 
Appreciate any help. 
+0

쿼리가 올바르게 실행되고있는 것 같습니다. 문제는'res.rows [0] .c' 인 것 같습니다. 'rows [0]'어떤 타입이 반환되는지는 확실치 않지만'res.rows [0] [0]'을 시도한 행/col 타입 결과가 주어 졌습니까? – James

+0

시도했습니다 ... var count = res.rows [0] [0]; 오류 : Uncaught TypeError : 정의되지 않은 '0'의 속성을 읽을 수 없습니다. – Harry

+0

테이블이 비어있는 것처럼 들립니다 ... – James

답변

0
html5.webdb.Count=function() { 
    var db = html5.webdb.db; 
    db.transaction(function (tx) { 
    tx.executeSql('SELECT COUNT(*) AS c FROM yourtable', [], function (tx, r) { 
     console.log(r.rows.item(0).c); 
    }, function (tx, e) { 
     alert ("unknown: " + e.message); 
    }); 
    }); 
} 

내 데시벨이를 사용, 제임스

덕분에
0

나는 항상 작동 코드와 카운트 (*)

select COUNT(*) totalCount from tableName 

그래서 당신은 반환 COU에 액세스 할 수 있습니다에 액세스 할 수있는 적절한 방법 아래에 설명이 totalCount에 액세스하여 NTN을 확인하십시오.

console.log(r.rows.item(0).totalCount);