want to fetch data from two tables in mysql

3335 views php
-3

hello i want to display data from two tables meaning this table i need from it amount and created and the user_id i want to get the username from other table name is users withdraw table users table

<?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();
?> 

answered question

need the solve please

You join the user ID on the username? They are most likely not the same.

1 Answer

12

Try:

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

posted this

Have an answer?

JD

Please login first before posting an answer.