Hi. There are 12 records in the Object: object. 'que2' must equate to the variable 'querycount' so that I can use it to my condition. The problem is it won't equate.. why is that? Here's my code (javascript): var querycount; rbf_selectNumber("SELECT COUNT(1) FROM object", function(que2) { alert(que2); querycount = que2; } ); alert(querycount); the OUTPUT: que2 = 12 querycount = still undefined Is there a problem in my code? Same goes to SelectQuery & SelectValue, the result is undefined.. Thank You.
The result is 12 - please check your output.
the result is still undefined. By the way I'm using Rollbase.ph . Thanks for the reply
I got a similar problem because of a race condition.
Here is the solution:
var querycount;
rbf_selectNumber("SELECT COUNT(1) FROM object", function(que2)
{ querycount = que2; after(); } );
// depending on the timing at runtime, querycount may not be defined yet
// you have to wait for the callback function to return
after() {
// now querycount is defined
alert(querycount);
}
rbf_selectNumber API, like other AJAX-based APIs operates asynchronously. So the best approach would be to process result inside callback function rather than use global variable.
I will add this info to documentation.
You are right. The correct way should be:
rbf_selectNumber("SELECT COUNT(1) FROM object", callback_count);
function callback_count(querycount) {
alert(querycount);
}