在PHP中过滤MySQL数据以仅显示当前会话用户的数据? [英] Filtering MySQL data in PHP to only show data of the current session's user?

查看:43
本文介绍了在PHP中过滤MySQL数据以仅显示当前会话用户的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下PHP脚本,用于选择MySQL数据并在表中显示所有不同用户的数据.

I have the following PHP script that selects MySQL data and displays all the different users' data in a table.

我需要将该数据限制为仅该会话的已登录用户的数据.与仅使用单个ID一样,登录人员的姓名和电子邮件,而不是显示所有用户数据的表格.

What I need is to limit this data to only that of the logged-in user for that session. As in only the single ID, name and email of the person logged in instead of the table showing all user data.

我假设我需要"SELECT * FROM usertable where(something)=(something)",我只是不确定从这里到哪里.

I assume I need to "SELECT * FROM usertable where (something) = (something)", I'm just not sure where to go from here.

任何帮助将不胜感激.

<?php
$con=mysqli_connect("localhost","myusername","mypassword","mydatabase");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM usertable");

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>";

while($row = mysqli_fetch_array($result)) 
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['emailaddress'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

推荐答案

SESSION ID并不意味着您需要输入类似$ _SESSION ['user_id']的内容.

SESSION ID don't mean you need to make something like $_SESSION['user_id'].

请记住,SESSION就像幽灵一样,有时它可能会丢失而无法追踪.尝试使用简单的cookie来确认会话数据存储在数据库中.只需限制该Cookie,那么几次后,该Cookie将被销毁并更新为完全不同的值.

Remember SESSION is like ghost, sometime it's can be lost with no trace. Try to used simple cookie to confirm session data store within database. Just make a limit to that cookie, so after several time, the cookie will be destroy and renew with complete diferent value.

您的问题很简单,...

For your question is simple,...

SELECT * FROM 'tablename' WHERE 'table_field' LIKE 'table_value'

这篇关于在PHP中过滤MySQL数据以仅显示当前会话用户的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆