首页 > 解决方案 > 通过用户变量过滤以获取我需要的用户不起作用,还创建了从一个用户到另一个用户的链接

问题描述

所以我有这个页面来显示我所拥有的不同类型用户的信息。在学生的页面上,我试图在父标题下方的该页面上显示每个学生的家长,这样做的方法是将每个学生中的 parent_email 变量与每个家长中的电子邮件变量进行比较,并找到相同的那个然后将该父母的姓名显示为指向其详细用户页面的链接。

到目前为止,刚开始,我已经尝试做一个嵌套的 for 循环来比较两个变量,然后显示父级的名称或简单的东西让我知道父级已经找到但不幸的是,我能想到的每个解决方案都打破了网站上的页面。这是我拥有的代码(一些注释代码是我尝试过的解决方案的一部分)。我对 php 和 html 不是很熟悉,所以任何帮助将不胜感激。谢谢!

函数内部没有进入比较电子邮件的 if 循环: if (users[i][1].parent_email == users[j][1].email)

function displayUsers(user_type)
{
    document.getElementById("user-list").style.display = 'block';
    firebase.database().ref('users').orderByChild('user_type').equalTo(user_type).once("value", function(snapshot)
    {

        if(user_type == "parent" || user_type == "student")
        {
            for(let i = 0; i < users.length; i++)
            {
                //table_rows += "<tr>";

                let name = users[i][1].first_name + " " + users[i][1].last_name;
                let key = users[i][0];

                for(let j = 0; j < users.length; j++)
                {
                    //table_rows += "<tr>";

                    let name1 = users[j][1].first_name + " " + users[i][1].last_name;
                    let key1 = users[j][0];

                    if (users[i][1].parent_email == users[j][1].email)
                    {
                        //table_rows += users[i][1].parent_email;
                        //table_rows += "<tr>";
                        if (user_type == "student")
                        {
                            table_rows += "<tr>";
                            table_rows += `<td id='name1-` + j +`'>
                                                <button class="rounded user-info-btn" type="button">
                                                    <a id='name1-link-${j}' style="color:white" href="detailed_user_info.php?key=${key1}&type=${users[j][1].user_type}">${name1}<a>
                                                </button>
                                            </td>`;
                        }

                        if (user_type == "parent")
                        {
                            table_rows += "<tr>";
                            table_rows += `<td id='name-` + i +`'>
                                    <button class="rounded user-info-btn" type="button">
                                        <a id='name-link-${i}' style="color:white" href="detailed_user_info.php?key=${key}&type=${users[i][1].user_type}">${name}<a>
                                    </button>
                                </td>`;
                        }
                    }
                }
            }
        }
    });
}

标签: javascripthtmldatabasefirebase

解决方案


推荐阅读