Using php code to display mysql database table content with userid

Good day,
Please I need help on how to fetch data table from the database with userid .
userid was concatenated with the database name.
database name concatenated with userid are the names of the tables in the database.
when a user login and want to view its table it will bring the exact table for the user to view.
Bellow is the code.
Thanks

session_start();
//include('verified_functions.php')

/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "123456", "mem_acct");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Attempt select query execution
// $sender_id=$ <em>SESSION["user"];
$sql="SELECT * FROM mem_acct</em> ".$_SESSION["userid"];
//$sql = "SELECT * FROM mem_acct_01212155";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo '<div class=" table-responsive">';
echo '<center><table class=" table table-striped" border="0" cellspacing="10" cellpadding="10" ></center>';
echo "<b> <center><h1>SAVING ACCOUNT</h1></center> </b> <br> <br>";


        echo "<tr>";
            echo '<th style=" text-align: center; ">POSTED DATE</th>';
            echo '<th style=" text-align: center; ">PAYMENT DATE</th>';
            echo '<th style=" text-align: center; ">DETAILS</th>';
            echo '<th style=" text-align: center; ">DEPOSIT</th>';
            echo '<th style=" text-align: center; ">WITHDRAWAL</th>';
            echo '<th style=" text-align: center; ">BALANCES</th>';
        echo "</tr>";
    while($row = mysqli_fetch_array($result)){
        echo '<tr style=" text-align: center; ">';
            echo "<td>" . $row['date_posted'] . "</td>";
            echo "<td>" . $row['payment_date'] . "</td>";
            echo "<td>" . $row['details'] . "</td>";
            echo "<td>" . $row['deposit'] . "</td>";
            echo "<td>" . $row['withdrawal'] . "</td>";
            echo "<td>" . $row['balance'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    echo"</div>";
    // Free result set
    mysqli_free_result($result);
} else{
    echo "No records matching your query were found.";
}

} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>STATEMENT</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0">
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="js/jquery-ui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="js/jquery-ui/jquery-ui.theme.css">
<link rel="stylesheet" type="text/css" href="mem_reg_style.css">
<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<style type="text/css">

body{ font: 14px sans-serif; }
</style>

</head>

Why would you possibly have the user have their own table?

If that is your actual code, I see a problem other than the whole, you shouldn’t do things this way to begin with.

Good day,
Thanks, I really appreciate you.
I will not mind if you can assist in other to solve the problem,
Thanks once again.

I will also like to know if there are better ways to do it. Thanks.

You have a user table and a transaction table. The transaction is bound to a user. When you query you search based on the user and maybe the type.

Sponsor our Newsletter | Privacy Policy | Terms of Service