如何从2个表中选择信息?

时间:2015-02-02 20:03:52

标签: php mysqli

我试图从两个表中获取数据:

$con = getDbConnect();
$edit = $_GET['edit'];

if (mysqli_connect_errno($con)) {
    "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
    $result = mysqli_query($con, "SELECT * FROM admininfo where email='" . $edit . "'");
    $results = mysqli_query($con, "SELECT * FROM adminaccount where email='" . $edit . "'");

while ($admininfo = mysqli_fetch_array($result, $results)) {

1 个答案:

答案 0 :(得分:1)

无论您选择多少个表格,都可以使用单个查询,例如

SELECT a.*, b.* FROM table1 a, table2 b where a.id = ? AND b.id = ?

然后,您从结果中获取所需内容,请查看docs

- 当然,不要使用select *