显示DB表的所有内容,而不仅仅是单行?

时间:2015-09-09 06:03:34

标签: php mysql

我想从数据库中显示该表的所有数据。我能够显示一行数据但我想显示所有内容吗?

views.php

         <?php
            $objUser=new User();
            $id=isset($_SESSION['uid']) ? $_SESSION['uid'] : '';
            $objUser->setuid($id);
            $data_list=$objUser->getalluser();
            //$row=$objUser->getalluser();

            ?>


            <div id="page-wrapper">
                        <div class="row">
                            <div class="col-lg-12">
                                <h1 class="page-header"><i class="fa fa-cog fa-fw"></i><span class="blue-word">User Setting</span></h1>
                            </div>


                                    <!--<?php //echo "<img src=\"Uploads/{$data_list['admin_img']}\" alt='{$data_list['admin_img']}' class='img-circle'  "?>-->

                            <?php



                                echo $data_list['admin_name'];

                                ?>

user.class.php

<?php
class User extends Connection
{
    private $admin_id;
    private $admin_email;
    private $admin_username;
    private $password;
    private $ip_used;
    private $login_date;
    private $acces_level;
    private $admin_img;


    public function setuid($ud='')
    {
        return $this->admin_id=$ud;
    }

    public function getIp_used()
    {
        return $this->ip_used;
    }
    //public function setadmin_img($aimg='')
   // {
    //    $this->admin_img=$aimg;
    //}
    public function setIp_used()
    {
        $this->ip_used=$_SERVER['REMOTE_ADDR'];

    }
    public function getaccess_level()
    {
        return $this->access_level;
    }
    public function setaccess_level($al="")
    {
        $this->access_level=$al;
    }
    public function getAdmin_email()
    {
        return $this->admin_email;
    }
    public function setAdmin_email($adem='')
    {
        $this->admin_email=$adem;
    }
    public function getAdmin_username()
    {
        return $this->Admin_username;
    }
    public function getPassword()
    {
        return $this->password;
    }
    public function setAdmin_username($uname='')
    {
        $this->Admin_username=$uname;

    }
    public function setPassword($upass='')
    {
        $this->password=sha1($upass);
    }
    public function setlogin_date()
    {

        $this->login_date=date('y-m-d h:i:s');
    }
    public function setimg_name($imgn='')
    {
        $this->img_name=$imgn;
    }
    public function getalluser()
{
$this->sql="SELECT * FROM admin_data";
$this->res=mysqli_query($this->conxn,$this->sql) or die($this->error=mysqli_query($this->conxn));
$this->numRows=mysqli_num_rows($this->res);
    $this->arr=array();
    if($this->numRows>0)
    {
        $this->data=mysqli_fetch_assoc($this->res);
        array_push($this->arr,$this->data);
    }

    return $this->data;
    //return TRUE;
}

}

我想显示表 admin_data 的全部内容。我可以使用for循环并检查变量$i < $numrows,但在这种情况下我不知道如何做到这一点?

2 个答案:

答案 0 :(得分:1)

如果要显示必须执行的所有行:

foreach($yourRows as $row) {
echo $row;
}

这就是你需要做的一切;)

答案 1 :(得分:1)

如果要一次获取整个结果,必须使用mysqli_fetch_all。 在你的情况下是:

$this->data = mysqli_fetch_all($this->res, MYSQLI_ASSOC);