Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sqlite 获取表中的记录数_Sqlite_Html - Fatal编程技术网

Sqlite 获取表中的记录数

Sqlite 获取表中的记录数,sqlite,html,Sqlite,Html,我有下面一段代码,它应该能够记录到控制台的记录数(如果表subjects存在) 实际上,result.rows被记录为未定义,所以我甚至不能对其调用方法item(int index)。如何访问返回的记录数?您忘记了onSuccess回调函数中的tx参数。您的结果变量实际上就是事务对象 以下是更正后的代码: db = openDatabase("myDatabase", "1.0", "", 200000); db.transaction(function(tx) { tx.execut

我有下面一段代码,它应该能够记录到控制台的记录数(如果表
subjects
存在)


实际上,
result.rows
被记录为未定义,所以我甚至不能对其调用方法
item(int index)
。如何访问返回的记录数?

您忘记了onSuccess回调函数中的
tx
参数。您的
结果
变量实际上就是事务对象

以下是更正后的代码:

db = openDatabase("myDatabase", "1.0", "", 200000);

db.transaction(function(tx) {
    tx.executeSql("SELECT COUNT(*) AS nor FROM subjects", [],
        function(tx, result){ // <-- this is where you forgot tx
            console.log(result.rows);
        },
        function(tx, error){
            tx.executeSql("CREATE TABLE subjects (id REAL UNIQUE, name TEXT)");
        }
    );
});
db=openDatabase(“myDatabase”、“1.0”、“200000”);
数据库事务(功能(tx){
tx.executeSql(“选择COUNT(*)作为主题的nor”,[],
函数(tx,result){//
db = openDatabase("myDatabase", "1.0", "", 200000);

db.transaction(function(tx) {
    tx.executeSql("SELECT COUNT(*) AS nor FROM subjects", [],
        function(tx, result){ // <-- this is where you forgot tx
            console.log(result.rows);
        },
        function(tx, error){
            tx.executeSql("CREATE TABLE subjects (id REAL UNIQUE, name TEXT)");
        }
    );
});