-1

I'm using Cordova Database and I have to display my images in the database randomly. Sqlite order by Random() is not working ... Here is my code

Var myDB = window.openDatabase("Database", "1.0", "Cordova Demo",10485760);
myDB.transaction(function(transaction) {

    transaction.executeSql('SELECT * FROM YOUTUBE_VIDEOO ORDER BY RANDOM LIMIT 6 ', [], function(tx, res){
        for(var iii = 0; iii < res.rows.length; iii++)
        {
            $('#uTubeLst').append("<div style='float:left;padding:10px;'><img src ='data:image/png;base64,"+res.rows.item(iii).imgSRc+"' width=40 height=50  ></div>");
        }

        function(transaction){

            var $lastNo = "";
        }
    }, null);
});
vidriduch
  • 4,753
  • 8
  • 41
  • 63
gStephin
  • 332
  • 3
  • 20

1 Answers1

2

I think you have to use braces because RANDOM() is a function, so your query string would look something like

'SELECT * FROM YOUTUBE_VIDEO ORDER BY RANDOM() LIMIT 6'

UPDATE

This seems to have a really poor performance, look at this thread for informations and alternatives: Select random row(s) in SQLite

Community
  • 1
  • 1
xaggre
  • 128
  • 6