Should the user's balance be stored in a separate table or within the banner table for a bannertausch system?

Storing the user's balance in a separate table is a better practice as it separates concerns and makes the database more organized. This also allows for easier manipulation of the user's balance without affecting the banner table. By keeping the balance in a separate table, it can be easily accessed and updated without the need to modify the banner table structure.

// Create a separate table for user balances
CREATE TABLE user_balances (
    user_id INT PRIMARY KEY,
    balance DECIMAL(10,2) DEFAULT 0
);

// Sample query to retrieve user balance
$user_id = 1;
$query = "SELECT balance FROM user_balances WHERE user_id = $user_id";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$user_balance = $row['balance'];