Separate, but also beginner question. When doing a join query like this, how do I pull the ID I want into my html table when the columns in both database tables are called “id”?
Example:
$query = "SELECT * FROM users u JOIN role r ON u.role_id = r.id LIMIT $start, $display";
$result = @mysqli_query ($dbc, $query);
echo "<table class='printTable'><tr>
<th>Role</th><th>First Name</th><th>Last Name</th><th>Email</th><th>Address</th><th>City</th><th>State</th><th>Zip</th><th>Phone</th><th>*</th><th>*</th></tr>";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>
<td>".$row['role']."</td>
<td>".$row['first_name']."</td>
<td>".$row['last_name']."</td>
<td>".$row['email']."</td>
<td>".$row['home_address']."</td>
<td>".$row['city']."</td>
<td>".$row['state']."</td>
<td>".$row['zip']."</td>
<td>".$row['phone']."</td>
<td><a href=deleteconfirm.php?id=".$row['id'].">Delete</a></td>
<td><a href=updateform.php?id=".$row['id'].">Update</a></td>
</tr>";
The last part:
<td><a href=deleteconfirm.php?id=".$row['id'].">Delete</a></td>
is pulling the ID for the role table, but I want to pull the ID for the users table.
I’ve tried $row[‘id’] , $row[‘u.id’], $row[‘u’.‘id’] but it either doesn’t work, does nothing, or gives an error.
Subsequent question, why does it default to pulling r.id? I am not sure how it decides that. You’ve been very helpful so far and I really appreciate it! I did go back and update a lot of my code throughout the project… and while I haven’t fixed my problem (yet!) I fixed a lot of other problems