简体   繁体   English

PHP-MySQL基于用户登录的表

[英]PHP - table from MySQL based on user logged in

Im new to PHP and mysql. 我是PHP和mysql的新手。

Currently I have a mysql database table which I query via a PHP script to display all the data via the browser. 目前,我有一个mysql数据库表,可以通过PHP脚本查询该表,以通过浏览器显示所有数据。 Currently, the format of the PHP table is same as the mysql table structure. 当前,PHP表的格式与mysql表的结构相同。

It displays the following currently. 当前显示以下内容。

Name      IPaddress   owner

test.com  192.1.12.1  someone

So three columns are displayed showing name, ipaddress, owner. 这样将显示三列,分别显示名称,ipaddress和所有者。

PHP snippet of how I get the data from mysql table: 我如何从mysql表获取数据的PHP代码段:

$sql = "select * from servers;";
$result = $db->query($sql);

while($row = $result->fetch_assoc()){
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['IPaddress'] . '</td>';
echo '<td>' . $row['Owner'] . '</td>';

}

So I go onto my PHP page and it displays all the results as expected. 因此,我进入我的PHP页面,它按预期显示了所有结果。 However, what I would like to do is for two users to be able to log in and if they are in Owner field they see their servers only. 但是,我想让两个用户登录,如果他们在“所有者”字段中,则只能看到他们的服务器。 So basically display my servers to owners only and to owners, their server only. 因此,基本上只将我的服务器显示给所有者,也只显示给所有者,即他们的服务器。

Can someone help me out with this? 有人可以帮我这个忙吗?

I suppose to have the user that match owner (name or id will differ however) inside a var called $user 我想在一个名为$user变量中包含与所有者匹配的用户(名称或ID将有所不同)

$sql = "SELECT * FROM servers WHERE owner='".$user."'"; //For $user = string
$sql = "SELECT * FROM servers WHERE owner=".$user; //For $user = integer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM