Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Picker only showing one value from database

My friends,

I have a picker pulling from a database but it only shows the first entry. I have tried various methods to pull all entries, but constantly get errors like missing semi-colon when I try to add a while loop or something to the pickerValues array even when I'm pretty sure there shouldn't be a semi-colon. The simple code is this:

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

//  picker initialization
var picker = Titanium.UI.createPicker({top:0});
picker.selectionIndicator=true;
var pickerValues = [

    Titanium.UI.createPickerRow({title:rows.fieldByName('styleName'),id:rows.fieldByName('styleID')})

];

picker.add(pickerValues);
pickerView.add(picker);

I'm used to PHP and I think I keep trying to make calls that Titanium doesn't like. I am slowly getting used to the way it functions.

Thanks in advance,
Eric

— asked July 15th 2010 by Eric Rodrigue
  • database
  • picker
  • values
0 Comments

2 Answers

  • Accepted Answer

    I think the problem is how you get the database rows.

    try like this:

    pickerValues = [];
    
    while (rows.isValidRow())
    {
    pickerValues.push(  Titanium.UI.createPickerRow({title:rows.fieldByName('styleName'),id:rows.fieldByName('styleID')}) )
    }
    
    picker.add(pickerValues);
    

    //code untested

    — answered July 15th 2010 by Dan Tamas
    permalink
    0 Comments
  • Thanks for the quick reply Tamas. Sorry I took so long to get back with you. I was on the road for 3 hours.
    Your code pointed me in the right direction. I had tried something similar only to get the missing semi-colon error. I got the error when adding yours, but I added a semi-colon to end of your pickerValues.push statement and the error when away but the window was completely blank. I added rows.next(); and rows.close(); to the end and voilá. It worked like it should. Below is the final code that worked for anyone needing something similar.

    Thanks again, Tamas

    while (rows.isValidRow()){
    pickerValues.push(
        Titanium.UI.createPickerRow({title:rows.fieldByName('styleName'),id:rows.fieldByName('styleID'),value:rows.fieldByName('styleID')})
    );
    rows.next();
    }
    rows.close();
    
    — answered July 15th 2010 by Eric Rodrigue
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.