Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

if-else conditional

$
0
0

Application type: mobile Titanium SDK: 3.2.3 Platform & version: iOS 7 Device: iOS simulator Host Operating System: OSX 10.9.3

Hi, basically my question is what is wrong with my if-else conditional statement?

var dataBrand = [];
 
if(dataBrand.length == 0){
 
    var db = Ti.Database.open('iowner');
        var brandRows = db.execute('SELECT * FROM brand');
        while(brandRows.isValidRow()){
            dataBrand.push({
                id: brandRows.fieldByName('brandID'),
                title: brandRows.fieldByName('brandName')
            });
            var brandid = brandRows.fieldByName('brandID');
            var brandname = brandRows.fieldByName('brandName');
            Ti.API.info(brandid + " " + brandname);
            brandRows.next();
        }
        brandRows.close();
 
    alert(dataBrand.length);
}else{
    var db = Ti.Database.open('iowner');
            var brandRows = db.execute('SELECT * FROM brand WHERE brandName <> ?', 'empty');
            while(brandRows.isValidRow()){
                dataBrand.push({
                    id: brandRows.fieldByName('brandID'),
                    title: brandRows.fieldByName('brandName')
                });
                var brandid = brandRows.fieldByName('brandID');
                var brandname = brandRows.fieldByName('brandName');
                Ti.API.info(brandid + " " + brandname);
                brandRows.next();
            }
            brandRows.close();
    alert('not empty!');
}
the scenario is i have in my database table: brand brandID = 0 brandName = empty

as a base enty

in the if-statement, when its dataBrand array length is 0. the picker (code not shown) will display 'empty'. and when i add new entry for example: brandID = 1 (auto) brandName = Top King

the else-statement will run, and as you can see in the query; only 'Top King' will be displayed

but unfortunately, the picker shows both 'empty' and 'Top King'. I then found out that the code actually never goes to else-statement eventhough when you check with

alert(dataBrand.length);
the condition 'dataBrand.length' is supposed to be running the else-statement

is there anyone here really understands what is going on?


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>