Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:12:46+00:00 2026-06-13T04:12:46+00:00

I am attempting to pull data from the local database and display it in

  • 0

I am attempting to pull data from the local database and display it in a tableview that uses a custom row. I do not know how to get it to display properly. the way it is currently written will display one row with the data correctly displayed in it, but it appears to be showing thousands of empty rows. I think my problem is because I have two while (rows.isValidRow()) statements. Would someone please show me the code to make this display correctly? Here is my current code:

//Setup the window
var win = Titanium.UI.currentWindow;
win.barColor='#000000';

//install database
var db = Ti.Database.install('bcapool3.sqlite','distributor');

//Get data
var rows = db.execute('SELECT * FROM distributor');

// create table view
var tableview = Ti.UI.createTableView({
    backgroundColor:'transparent',
    color: '#000000',
    top:80,
    height:'auto',
    left:80,
    right:80,
    bottom:120
});


function setData() {

while (rows.isValidRow())
{
var dataArray = [];
var row = Ti.UI.createTableViewRow({
    haschild: true,
    path: 'distributordetail.js'
});
    var title = Ti.UI.createLabel({ 
    color:'#000000',
    height:32,
    left:5,
    top:2,
    font:{fontSize:'18dp',fontWeight:'bold' },
    backgroundColor:'transparent',
    text:'' + rows.fieldByName('distributor_name') + ''
    });

    var address = Ti.UI.createLabel({   
    color:'#000000',
    height:32,
    left:5,
    top:34,
    fontSize:'14dp',
    backgroundColor:'transparent',
    text:'' + rows.fieldByName('distributor_address') + ''
    });

    var distance = Ti.UI.createLabel({  
    color:'#000000',
    height:32,
    right: 10,
    top:34,
    fontSize:'12dp',
    backgroundColor:'transparent',
    text:'' + rows.fieldByName('distance') + ''
    }); 

    row.add(title);
    row.add(address);
    row.add(distance);
    tableview.add(row);
    row.className = 'distributorRow';

    dataArray.push(row);
    rows.next();    
}

// set the array to the tableView
tableview.setData(dataArray);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:12:47+00:00Added an answer on June 13, 2026 at 4:12 am

    You are right, 2 while loops are making problem.
    Also you need to add rows to dataArray : dataArray.push(row);

    And then outside of while loop, set dataArray as data to tableView: tableview.setData(dataArray);

    I just modified some of your code and it is working fine:

    //Setup the window
    var win = Titanium.UI.createWindow({
        backgroundColor: '#123456',
    });
    
    //install database
    var db = Ti.Database.open('distributor');
    try{
        db.execute('create table if not exists distributor(id varchar(10), distributor_name varchar(10), distributor_address varchar(10), distance varchar(10));');
        db.execute("Insert into distributor values('id1','name1','address1','distance1')");
        db.execute("Insert into distributor values('id2','name2','address2','distance2')");
        db.execute("Insert into distributor values('id3','name3','address3','distance3')");
        db.execute("Insert into distributor values('id4','name4','address4','distance4')");
        db.execute("Insert into distributor values('id5','name5','address5','distance5')");
    }
    catch(err)
    {
        Ti.API.info(err.message);
    
    }
    
    
    
    // create table view
    var tableview = Ti.UI.createTableView({
        backgroundColor:'transparent',
        color: '#000000',
        top:80,
        height:'auto',
        left:80,
        right:80,
        bottom:120
    });
    
    setData();
    win.add(tableview);
    win.open();
    
    
    function setData() {
        //db.open();
        var rows = db.execute('SELECT * FROM distributor');
        //db.close();
        var dataArray = [];
        while (rows.isValidRow())
        {
            var row = Ti.UI.createTableViewRow({
                haschild: true,
            });
            var title = Ti.UI.createLabel({ 
                color:'#000000',
                height:32,
                left:5,
                top:2,
                font:{fontSize:'18dp',fontWeight:'bold' },
                backgroundColor:'transparent',
                text:'' + rows.fieldByName('distributor_name') + ''
            });
            var address = Ti.UI.createLabel({   
                color:'#000000',
                height:32,
                left:5,
                top:34,
                fontSize:'14dp',
                backgroundColor:'transparent',
                text:'' + rows.fieldByName('distributor_address') + ''
            });
            var distance = Ti.UI.createLabel({  
                color:'#000000',
                height:32,
                right: 10,
                top:34,
                fontSize:'12dp',
                backgroundColor:'transparent',
                text:'' + rows.fieldByName('distance') + ''
            });
            row.add(title);
            row.add(address);
            row.add(distance);
            dataArray.push(row);
            rows.next();     
        }
        tableview.setData(dataArray);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to pull some data from a SQLite database so that I can
I'm attempting to pull data from a page that a user is viewing and
I am attempting to pull down data from a JSON response that I wrote
I've been attempting to pull hard-coded configuration data from a Tomcat web-app which I'm
I'm attempting to create an app to pull the sqlite data from a preexisting
I am attempting to make a program that will pull data such as OS,
I've created a Gridview control that pulls some data from my database, but doesn't
I'm attempting to pull data from a stored procedure using PDO, and I'm having
I'm attempting to pull in data from Google's Shopping API. I'm able to download
Using MarkLogic to pull in data from a web service with xdmp:http-get() or xdmp:http-post()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.