5

I am using Phonegap sqlite.

I have one table in my database named "Phone" in which I have 3 columns.

Table structure is:

ID PhoneName Version 1 A 1.3 2 B 3.4 

I am getting the value of ID.

How do I retrieve the value of PhoneName from table?

0

2 Answers 2

9

Using cordova 2.7.0 I did it the following way.

document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { app.initialize(); getSingleRow(10); getMultipleRows(); } //Single row function getSingleRow(id) { db.transaction ( function (tx) { tx.executeSql ( 'SELECT ColumnName FROM tableName WHERE ID=?', [id], function(tx,results) { var len = results.rows.length; if(len>0) { alert(results.rows.item(0)['ColumnName']); } }, errorCB ); },errorCB,successCB ); } //Multiple records function getMultipleRows() { db.transaction ( function (tx) { tx.executeSql ( 'SELECT ColumnName FROM tableName', [], function(tx,results) { var len = results.rows.length; if(len>0) { for (var i = 0; i < len; i++) { alert(results.rows.item(i)['ColumnName']); } } }, errorCB ); },errorCB,successCB ); } 

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this.

 function devicereadyFun(){ var dBase = window.sqlitePlugin.openDatabase({ name: 'ebe.db', location: 'default' }); dBase.executeSql("select * from Phone where ID = ?", ['1'], function(rsp){ alert(rsp.rows.item(0).ID); alert(rsp.rows.item(0).PhoneName); alert(rsp.rows.item(0).Version); }); } document.addEventListener('deviceready', devicereadyFun, false); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.