如何使用session从数据库中检索名字

时间:2017-08-21 01:49:53

标签: php

我想显示登录我网站的数据库的名字 - 而不是用户的用户名。 这是我的数据库的图片,所以我已经尝试过查询,但总是抱怨一个未定义的索引  this is from database

这是导航栏出勤,只有另一个导航栏,但我只举例说明

navbar_attendance.php

def staff_visible(self):
  queryset = self.filter(Q(staff_visible=True))
  return queryset

def visible(self):
  queryset = self.filter(is_active=True)
  return queryset

session.php文件

Product.objects.staff_visible()

1 个答案:

答案 0 :(得分:-1)

您好,您需要将此查询放在要显示名字的位置。

       <?php if(!isset($_SESSION)){


    session_start();

    } ?>  
    <div class="navbar navbar-fixed-top navbar-inverse">
                <div class="navbar-inner">
                    <div class="container">
                        <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </a>


    <div class="nav-collapse collapse">
                        <ul class="nav">




        <li><a href="dashboard.php"><i class="icon-home icon-large"></i>&nbsp;Home</a></li>




         <li><a href="attendance.php"><i class="icon-home icon-large"></i>&nbsp;Attendance Info</a></li>


            <li><a href="users.php"><i class="icon-user icon-large"></i>&nbsp;Users</a></li>


        <?php 
                        include('dropdown.php');
                        ?>


        <li><a href="books.php"><i class="icon-book icon-large"></i>&nbsp;Books</a></li>


        <li><a href="member.php"><i class="icon-group icon-large"></i>&nbsp;Member</a></li>


        <li ><a href="archive.php"><i class="icon-list-alt icon-large"></i>&nbsp;Archive</a></li>


        <li><a href="utility.php"><i class="icon-cog icon-large"></i>&nbsp;Utilities</a></li>


            <li><a href="logout.php"><i class="icon-signout icon-large"></i>&nbsp;Logout</a></li>
                        </ul>


                         <div class="pull-right">
                            <div class="admin">Welcome: <?php


        if(isset($_SESSION['id'])){

 $sql="SELECT firstname FROM TABLENAME WHERE user_id='$session_id'";
     $result=mysqli_query($link,$sql);
     if(mysqli_num_rows($result)>0)
    {
    while($row=  mysqli_fetch_assoc($result)){
             echo $row['firstname'];
                       }
                   }

        }

        ?></div>
                         </div>
                        </div>
                    </div>
                </div>
            </div>

             <?php include('search_form.php'); ?>`