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

  • Home
  • SEARCH
  • 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 6743305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:56:44+00:00 2026-05-26T11:56:44+00:00

I’m having a problem with some code not performing as expected, I should probably

  • 0

I’m having a problem with some code not performing as expected, I should probably explain what it’s doing first:

  • On document load function selectForLists is querying a sqlite DB
    containing football scores, specifically a table called matches, then
    calling function renderLists.

  • RenderLists puts the playing team into a sorted list with duplicates
    removed.

  • Then for each entry in this list of teams function latestTest is
    being called, which selects all rows from the match table where that
    team is playing and calls latestTest2.

  • LatestTest2 counts the number of rows with that team playing and
    outputs some code to the inserted div.

  • Once that has been completed for every team it should revert to
    finish the renderLists function and call the loaded function, except
    it doesnt and I have to add a delay to calling this function because
    it doesnt happen last.

I’m hoping someone can tell me whats wrong here, why the loaded function isn’t called after all the above is completed? Also if anyone has any tips for achieving the same outcome with more efficient code I would like that very much.

Apologies for this long post, I’m sure many will find the code terrible and I know there are too many functions and probably many better ways of doing this but its been a few years since working with javascript in uni and I’m struggling with it and sqlite.

The code is below or at http://pastebin.com/7AxXzHNB thanks

function selectForLists() { //called on (document).ready
    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM matches', [], renderLists);
    });
}

function renderLists(tx, rs) {
    var playingList = new Array();
    for (var i = 0; i < rs.rows.length; i++) {
        playingList.push(rs.rows.item(i)['playing']);
    }

    playingListSort = playingList.sort();
    var playingListFinal = new Array();

    playingListSort.forEach(function(value) {
        if (playingListFinal.indexOf(value) == -1) {
            playingListFinal.push(value);
        }
    });

    for (var c = 0; c < playingListFinal.length; c++) {
        latestTest(playingListFinal[c]);
    }

    loaded(); //not running last in the function
    //setTimeout(loaded,1000);
    /////Using a delay because it doesn't run after the above has completed
}

function latestTest(team) {
    db.transaction(function(tx) {
        tx.executeSql('SELECT * FROM matches WHERE playing="' + team + '"', [], latestTest2);
    });
}

function latestTest2(tx, rs) {
    counted = rs.rows.length;
    var theFunction = rs.rows.item(0)['playing'];

    $('#inserted').append('<li onclick="onToDate(\'' + theFunction + '\')"><img width="30px"        height="25px" id="popupContactClose" src="style/soccer.png"><div id="popupContactClose2">' + counted + '</div></img>' + rs.rows.item(0)['playing'] + '</li>');
}
  • 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-05-26T11:56:44+00:00Added an answer on May 26, 2026 at 11:56 am

    The latestTest function calls another executeSQL function with its own callback. That callback will be executed when the SQL has finished, which will be at an arbitrary time.

    The renderLists function will continue execution (including calling the loaded function) normally, quite apart from anything having to do with the callbacks in latestTests being executed.

    Your mistake is thinking that loaded will “wait” to be executed–you will still have pending callbacks from the DB code in latestTest.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.