Web数据库子查询
我正在努力使用 JavaScript 函数从 2 个不同的查询中获取数据。如果我在函数中单独执行查询,我只能从第二个查询中的第一个查询中获得最后的结果。我得出的结论是,我必须对这两个查询进行子查询,以便该函数能够正常运行。
以下是两个查询 (popt.products_options_id = prodOpId
):
tx.executeSql('
SELECT DISTINCT
popt.products_options_id,
popt.products_options_name
FROM
products_options popt,
products_attributes patrib
WHERE
patrib.products_id="1"
AND
patrib.options_id = popt.products_options_id
AND
popt.language_id = "1"
ORDER BY
popt.products_options_name',
[], function (tx, results) {
tx.executeSql('
SELECT
pov.products_options_values_id,
pov.products_options_values_name,
patrib.options_values_price,
patrib.price_prefix
FROM
products_attributes patrib,
products_options_values pov
WHERE
patrib.products_id = "1"
AND
patrib.options_id ='+ prodOpId + '
AND
patrib.options_values_id = pov.products_options_values_id
AND
pov.language_id = "1"',
[], function (tx, results) {
I'm struggling with a JavaScript function to get data from 2 different queries. If I execute the queries separated in the function, I only get the last result from the first in the second query. I have come to the conclusion that I have to subquery the 2 queries so the function will run properly.
Here are both queries (popt.products_options_id = prodOpId
):
tx.executeSql('
SELECT DISTINCT
popt.products_options_id,
popt.products_options_name
FROM
products_options popt,
products_attributes patrib
WHERE
patrib.products_id="1"
AND
patrib.options_id = popt.products_options_id
AND
popt.language_id = "1"
ORDER BY
popt.products_options_name',
[], function (tx, results) {
tx.executeSql('
SELECT
pov.products_options_values_id,
pov.products_options_values_name,
patrib.options_values_price,
patrib.price_prefix
FROM
products_attributes patrib,
products_options_values pov
WHERE
patrib.products_id = "1"
AND
patrib.options_id ='+ prodOpId + '
AND
patrib.options_values_id = pov.products_options_values_id
AND
pov.language_id = "1"',
[], function (tx, results) {
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了当前查询的问题:
i fixed my problem with the current query: