I'm new to the community and would love a push into the right direction. Just started working with php for a few days and I ran into something I just can't get right. Could you guys help me out?
<?php
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
if (!$result) {
die("Invalid query: " . $conn->error);
}
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["role"] . "</td>
</tr>";
}
?>
This is an example code of what I'm working on. This code works, I have a separate file for the connection that's included in my code. I'm displaying all the rows from the database table "users" with the contents of "role". That works, but that's not what want to show.
This is what I'm trying to do and I can't get my head around it. I want to compare the value of "role" with the value of "role" in a different table: "roles". If it matches, I want to show the value of "rolename" out of the "roles" table out of the row that matches the "role" from the "users" table. Does that make sense?
Thanks to whomever can help me out! :)