如何从数据库[HTML5]获取两个相同字段的数据?

发布于 2024-12-02 16:55:38 字数 1286 浏览 0 评论 0原文

this.db.transaction(function (tx)
            {
                tx.executeSql('SELECT tsk.*, cont.firstName, cont.lastName ,cont1.firstName, cont1.lastName, list.listId FROM tbl_tasks tsk, tbl_contacts cont,tbl_contactequests cont1, tbl_lists list WHERE  (tsk.assignedId=0 or tsk.assignedId=cont.contactId or tsk.assignedId=cont1.contactRequestId) and tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" and list.listId=tsk.listId and list.listId='+window.defaultlistid+' group by tsk.taskId', [], enyo.bind(this,this.queryResponse), enyo.bind(this,this.errorHandler));//call queryResponse
            }.bind(this));

现在您可以看到 cont.firstName (Table tbl_contacts) & cont1.firstName (表 tbl_contactequests) 与此循环具有相同的字段名字,

for (var i = 0; i < len; i++)
            {

                list[i]     =   results.rows.item(i);
                fname       =   list[i].firstName;
                lname       =   list[i].lastName;
                fullname    =   fname+' '+lname;
                //alert(fullname);
                if(list[i].assignedId==0)
                {list[i].name = '';}
                else
                {list[i].name=fullname;}

            }

我可以获取 tbl_contacts 字段名字的第一个值。现在假设我无法访问 tbl_contactequests 表名字。

this.db.transaction(function (tx)
            {
                tx.executeSql('SELECT tsk.*, cont.firstName, cont.lastName ,cont1.firstName, cont1.lastName, list.listId FROM tbl_tasks tsk, tbl_contacts cont,tbl_contactequests cont1, tbl_lists list WHERE  (tsk.assignedId=0 or tsk.assignedId=cont.contactId or tsk.assignedId=cont1.contactRequestId) and tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" and list.listId=tsk.listId and list.listId='+window.defaultlistid+' group by tsk.taskId', [], enyo.bind(this,this.queryResponse), enyo.bind(this,this.errorHandler));//call queryResponse
            }.bind(this));

Now as you can see cont.firstName (Table tbl_contacts) & cont1.firstName has (Table tbl_contactequests) has same fields first name

for (var i = 0; i < len; i++)
            {

                list[i]     =   results.rows.item(i);
                fname       =   list[i].firstName;
                lname       =   list[i].lastName;
                fullname    =   fname+' '+lname;
                //alert(fullname);
                if(list[i].assignedId==0)
                {list[i].name = '';}
                else
                {list[i].name=fullname;}

            }

with this loop i can able to featch first value of tbl_contacts field firstname.Now suppose if i can't to access tbl_contactequests table firstname.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝梦月影 2024-12-09 16:55:38

使用 AS 关键字进行 SQL 查询:

    'SELECT tsk.*, 
            cont.firstName AS cFirstName, 
            cont.lastName ,
            cont1.firstName AS c1FirstName, 
            cont1.lastName, list.listId 
     FROM tbl_tasks tsk, tbl_contacts cont,
          tbl_contactequests cont1, tbl_lists list 
     WHERE  (tsk.assignedId=0 OR tsk.assignedId=cont.contactId OR
            tsk.assignedId=cont1.contactRequestId) AND 
            tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" AND 
            list.listId=tsk.listId AND list.listId='+window.defaultlistid+' 
     GROUP BY tsk.taskId'

Use AS keyword for SQL query:

    'SELECT tsk.*, 
            cont.firstName AS cFirstName, 
            cont.lastName ,
            cont1.firstName AS c1FirstName, 
            cont1.lastName, list.listId 
     FROM tbl_tasks tsk, tbl_contacts cont,
          tbl_contactequests cont1, tbl_lists list 
     WHERE  (tsk.assignedId=0 OR tsk.assignedId=cont.contactId OR
            tsk.assignedId=cont1.contactRequestId) AND 
            tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" AND 
            list.listId=tsk.listId AND list.listId='+window.defaultlistid+' 
     GROUP BY tsk.taskId'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文