-1

我正在尝试获取所有用户输入都相同的行,但我正在尝试从多个表中获取值。

$query=
"SELECT * 
 FROM (client OR agent OR admin) 
 WHERE (first='".$mysqli->real_escape_string($_SESSION['first'])."' 
    AND last='".$mysqli->real_escape_string($_SESSION['last'])."' 
    AND password='".$mysqli->real_escape_string($_SESSION['pass'])."')";

有什么办法吗?

4

1 回答 1

1
<?php
$first = $mysqli->real_escape_string($_SESSION['first']);
$last = $mysqli->real_escape_string($_SESSION['last']);
$password = $mysqli->real_escape_string($_SESSION['pass']);

$query=
"SELECT *
 FROM client, agent, admin
 WHERE (client.first = '$fist' AND client.last = '$last' AND client.password = '$password')
 OR (agent.first = '$fist' AND agent.last = '$last' AND agent.password = '$password')
 OR (admin.first = '$fist' AND admin.last = '$last' AND admin.password = '$password')";

这是您获取数据的方式,但现在您必须检查存在哪些表数据,为此您可以使用mysqli_fetch_field

顺便说一句,考虑重新组织数据库表的选项,因为客户端、代理和管理员可以存储在一个users带有列的表中,type或者role代表客户端、代理或管理员。这种方法称为数据库规范化。之后,您的查询和数据获取将更加简单和快捷。

于 2012-11-03T10:17:45.270 回答