gpt4 book ai didi

php - 显示数据库表的所有内容,而不仅仅是单行?

转载 作者:行者123 更新时间:2023-11-29 07:31:34 24 4
gpt4 key购买 nike

我想显示数据库中表的所有数据。我可以显示单行数据,但我想显示所有内容?

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 来完成此操作但在这种情况下我不知道该怎么做?

最佳答案

如果你想显示所有行,你必须这样做:

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

这就是您需要做的全部;)

关于php - 显示数据库表的所有内容,而不仅仅是单行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32471967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com