繁体   English   中英

想从mysql中的两个表中获取数据

[英]want to fetch data from two tables in mysql

你好,我想显示两个表中的数据,这意味着我需要从它的数量和创建的这个表中获取用户 ID,我想从其他表名中获取用户名是用户提取表用户表

<?php
$servername = "localhost";
$username = "aa";
$password = "aat&IpnFt";
$dbname = "aa";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}



$sql = " SELECT withdraw.amount, withdraw.account, withdraw.created
FROM withdraw
INNER JOIN users ON withdraw.user_id=users.username; ";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["username"]. "   Name: " . $row["amount"]. "<br> " . $row["account"]. " " . $row["created"]. "<br>";
    }
} else {
    echo "Nothing Found!";
}
$conn->close();
?> 

您没有选择 table2 的用户名并将withdraw.user_id 与 users.username 进行比较

尝试:

$sql = " SELECT withdraw.amount, withdraw.account, withdraw.created, users.username
FROM withdraw
INNER JOIN users ON withdraw.user_id=users.id; ";

暂无
暂无

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

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