Note that there are some explanatory texts on larger screens.

plurals
  1. POPhoneGap + jQueryMobile - Populating database
    primarykey
    data
    text
    <p>I'm working with phonegap &amp; jquery mobile for a mobile native application.</p> <p>I have on html file multiple jquery mobile pages in it.<br> In my html file I have :</p> <pre><code>&lt;script type="text/javascript" charset="utf-8"&gt; // VARIABLES var db; // INIT FUNCTION function onBodyLoad(){ document.addEventListener("deviceready", onDeviceReady, false); } // ONDEVICE READY FUNCTION function onDeviceReady(){ db = window.openDatabase("shopit", "1.0", "SHOPIT DB", 1000000); // RETURN NEW DB OBJECT db.transaction(populateDB, onTxError, onTxSuccess); // POPULATE DB WITH SUPERMARKTES + SHOPS + CATEGORIES + PRODUCTS } // POPULATE DB function populateDB(tx) { // SUPERMARKETS tx.executeSql('DROP TABLE IF EXISTS SUPERMARKETS'); tx.executeSql('CREATE TABLE IF NOT EXISTS SUPERMARKETS (id, name, imgsrc)'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (1, "Aldi", "images/supermarkets/aldi.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (2, "Carrefour", "images/supermarkets/carrefour.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (3, "Colruyt", "images/supermarkets/colruyt.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (4, "Delhaize", "images/supermarkets/delhaize.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (5, "Intermarche", "images/supermarkets/intermarche.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (6, "Lidl", "images/supermarkets/lidl.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (7, "Ocool", "images/supermarkets/ocool.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (8, "Okay", "images/supermarkets/okay.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (9, "Smatch", "images/supermarkets/smatch.jpg")'); tx.executeSql('INSERT INTO SUPERMARKETS (id, name, imgsrc) VALUES (10, "Spar", "images/supermarkets/spar.jpg")'); } &lt;/script&gt; </code></pre> <p>Now my question is: "Will the function 'populateDB' be called everytime a page loads? And how can I change this it only loads one time?"</p> <p>My pages are structured like this in one html file:</p> <pre><code>&lt;div data-role="page" id="list"&gt; &lt;div data-role="header"&gt; &lt;div data-role="navbar" class="nav-glyphish-example" data-iconpos="bottom"&gt; &lt;ul&gt; &lt;li&gt;&lt;a id="currlist" href="#" data-icon="custom" &gt;My list&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="currlist" href="#" data-icon="custom" &gt;Producten&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="currlist" href="#" data-icon="custom" &gt;Favorieten&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a id="currlist" href="#" data-icon="custom" &gt;Promoties&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;ul data-role="listview" id="list"&gt;&lt;/ul&gt; &lt;/div&gt; &lt;div data-role="footer"&gt; &lt;h4&gt;SHOP-it Applicatie&lt;/h4&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="page" id="newlist"&gt; &lt;div data-role="header"&gt; &lt;h1&gt;Nieuwe lijst&lt;/h1&gt; &lt;/div&gt; &lt;div data-role="content"&gt; &lt;div data-role="controlgroup" data-type="horizontal"&gt; &lt;a href="#newlist" onclick="showSupermarkets();" data-role="button" data-theme="b"&gt;Supermarkten&lt;/a&gt; &lt;a href="#newlistshops" onclick="showShops();" data-role="button"&gt;Winkels&lt;/a&gt; &lt;/div&gt; &lt;div id="supermarkets"&gt; &lt;/div&gt; &lt;a href="#newlist_other" data-role="button"&gt;Andere lijst aanmaken&lt;/a&gt; &lt;/div&gt; &lt;div data-role="footer"&gt; &lt;h4&gt;SHOP-it&lt;/h4&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload