I am trying to learn about Foreign keys and being able to associated data from one table to another. So I have a users table and a cards table.
The user table has 'user_id', 'username' & 'email'. The card table has 'card_id' & 'name'.
what I am looking to do is associate a card form the card table to the users. so for example if the card table has Card1 inside and user1 wants that card (or more) assocaited with them how would I use the foreign key to do this.
Here is how I am selecting and showing my users at the moment:
<?php
$sql = "SELECT user_id, username, email_address FROM user";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo
$row["username"] . "<br>",
$row["email_address"] . "<br><br>";
}
} else {
echo "0 Members";
}
$conn->close();
?>
I understand inside of the user table I will need to another another cell 'card_id' but not sure on which data type this should be?