admin管理员组文章数量:1419656
I need to use javascript and HTML5 to display the result of the following SQL query in my html page. The SQL query works in SQLite Browser, but I am unsure of how to write the function and corresponding HTML5 code to call the function to display the result of my query. The SQL Query is as follows:
SELECT SUM(Orders.productQty * Products.productPrice) AS grandTotal FROM Orders JOIN Products ON Products.productID = Orders.productID
This returns a numerical result from my SQLite database that is already created, but I do not get how to display the result of the select query on my webpage.
I've tried using the following function to execute the sql statement, but I do not know how to display it using HTML.
function calculateTotalDue() {
db.transaction(function (tx) {
tx.executeSql('SELECT SUM(Orders.productQty * Products.productPrice) AS grandTotal FROM Orders JOIN Products ON Products.productID = Orders.productID', [], []);
});
}
Would someone please show me how to display the result of the query in my html page?
I need to use javascript and HTML5 to display the result of the following SQL query in my html page. The SQL query works in SQLite Browser, but I am unsure of how to write the function and corresponding HTML5 code to call the function to display the result of my query. The SQL Query is as follows:
SELECT SUM(Orders.productQty * Products.productPrice) AS grandTotal FROM Orders JOIN Products ON Products.productID = Orders.productID
This returns a numerical result from my SQLite database that is already created, but I do not get how to display the result of the select query on my webpage.
I've tried using the following function to execute the sql statement, but I do not know how to display it using HTML.
function calculateTotalDue() {
db.transaction(function (tx) {
tx.executeSql('SELECT SUM(Orders.productQty * Products.productPrice) AS grandTotal FROM Orders JOIN Products ON Products.productID = Orders.productID', [], []);
});
}
Would someone please show me how to display the result of the query in my html page?
Share Improve this question asked Jan 4, 2013 at 20:20 EzAnalystEzAnalyst 2533 gold badges4 silver badges12 bronze badges 2- Do you mean display the results of your query? – jsweazy Commented Jan 4, 2013 at 20:30
- Yes. Display the result on my html page, but there should only be one result, the sum. – EzAnalyst Commented Jan 4, 2013 at 20:38
1 Answer
Reset to default 1What you need is a function in the third parameter of the executeSql call. like this ( this is an example if you have mulitple results, but will work with your query too ):
Javascript
function calculateTotalDue() {
db.transaction(function (tx) {
tx.executeSql('SELECT SUM(Orders.productQty * Products.productPrice) AS grandTotal FROM Orders JOIN Products ON Products.productID = Orders.productID', [],
function(){
// Get return rows
var data = result.rows;
// Initialize variable to store your html
var html = '';
// loop thru results
for (var i = 0; i < dataset.length; i++) {
var row = data.item(i);
// Add to html variable
html += row.grandTotal;
// Append that html somewhere
// How todo this will vary depening on if you are using framworks or not
// If just javascript use:
// document.getElementById('results').innerHTML += html;
}
}
);
});
}
本文标签: javascriptDisplay SQL Query Result in HTMLStack Overflow
版权声明:本文标题:javascript - Display SQL Query Result in HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745315752a2653147.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论