I am a newbie to mysql, and originally I was going to create an enum datatype for my table but I found this question Create enum in SQL Server, and used it as a reference as that is what I needed. However when I tried to grab the data using the following sql statement it failed:
$sql = "
SELECT users.userID
, users.firstName
, users.lastName
, membersrank.rank
, memberstyle.style
FROM users
JOIN membersrank
ON membersrank.rankID = memberships.rankID
JOIN memberstyle
ON memberstyle.styleID = memberships.styleID
JOIN memberships
ON users.userID = memberships.userID
";
The prepare statement failed when I ran it. I assumed something is wrong with the sql statement.
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
header("location: /index.php?error=stmtFailed");
exit();
}
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
These two tables below are the "user_rank" table referenced from the link.
Table: membersrank Table: memberstyle
| rankID | rank | | styleID | style |
| -------- | -------- | | -------- | ------------ |
| 0 | Guest | | 0 | N/A |
| 1 | Member | | 1 | Casual |
| 2 | Admin | | 2 | Competitive |
Table: memberships (is it the table, 'users', from the link)
| membershipID | userID | rankID | styleID |
| ------------ | -------- | -------- | -------- |
| 0 | 1 | 1 | 1 |
| 1 | 2 | 2 | 1 |
| 2 | 3 | 1 | 0 |
Result im trying to achieve:
| userID | firstName | lastName | rank | style |
| ------------ | ---------- | -------- | -------- | -------- |
| 0 | John | Doe | Member | Casual |
| 1 | Jane | Doe | Admin | Casual |
| 2 | Joe | Smith | Member | N/A |
How do I go about this and what is the proper sql statement? (if need the unlisted table 'users' is required as info then is as you see in the my result table without the rank and style columns.)
Thanks in advance!