MySQLi Matching ID from different table

Daryin Littlejohn

Basically, I'm making a table that outputs people that have been banned. So far, I have everything done with MySQLi, just instead of showing the actual name it shows the player ID. I'm having trouble with this because the players ID is stored in a seperate table.

http://i.stack.imgur.com/sy6G9.png

This picture is the structure of the main table, notice player_id and creator_id? What I have to do is match the ID and replace the number with the row "name" accordingly from the other table shown below http://i.stack.imgur.com/Lm3Fg.png

If you could help me out, I'd appreciate it greatly.

immulatin

This query will just show you the names of the banned players:

SELECT name FROM banned_table INNER JOIN name_table ON player_id=name_table.id 

Of course you would need to change banned_table and name_table to the actual tablenames in your DB.

UPDATE: From the comments below this is the solution for the OP

SELECT b.*,n.name as player, n2.name as admin FROM banhammer_bans b 
JOIN name_table n ON b.player_id=n.id 
JOIN name_table n2 ON b.creator_id=n2.id
ORDER BY b.created_at DESC

And change the display code:

echo'<td>' . $row['player_id'] . '</td>';
echo'<td>' . $row['creator_id'] . '</td>';

To Be:

echo'<td>' . $row['player'] . '</td>';
echo'<td>' . $row['admin'] . '</td>';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mysqli join tables from 2 different databases

From Dev

Matching fighters from a single table

From Dev

MySQLI Select from table using prepared statments

From Dev

MySQL insert id values from other table into matching rows

From Dev

Select from a table values that have at least one row matching different requirements

From Dev

MySQLi select from two table with limit

From Dev

How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

From Dev

PHP/MySqli check table a ID against table B id

From Dev

Show Name Instead of ID from Different Table

From Dev

Take different names from the same column using two different ID's from other table

From Dev

display data from two table by matching id codeigniter

From Dev

How to count the number of occurrences of an ID from a different table

From Dev

update all values from different table that has same id

From Dev

Get a data from a different table using id

From Dev

Joining table with range ID matching

From Dev

How to order data with matching ID from another table using linq?

From Dev

Matching fighters from a single table

From Dev

ORDER BY # of rows with same option ID from different table

From Dev

Select from a table values that have at least one row matching different requirements

From Dev

MySQLi select from two table with limit

From Dev

Need Info from different id on the same table Laravel

From Dev

mysqli query from multiple table

From Dev

Iterating over all rows with the same id and find matching values in a different table

From Dev

mySQLi / PHP select row with highest index/id from all matching rows

From Dev

How to choose mysqli table id number from dropdown menu and output select values from that row

From Dev

Update Table by Matching Invoice ID

From Dev

Formatting mysqli output table with different functionalities

From Dev

Mysql : select from five different table where matching only one column based on a date or between dates

From Dev

Selecting Matching values from three different table and combining them in one table in Oracle

Related Related

  1. 1

    Mysqli join tables from 2 different databases

  2. 2

    Matching fighters from a single table

  3. 3

    MySQLI Select from table using prepared statments

  4. 4

    MySQL insert id values from other table into matching rows

  5. 5

    Select from a table values that have at least one row matching different requirements

  6. 6

    MySQLi select from two table with limit

  7. 7

    How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

  8. 8

    PHP/MySqli check table a ID against table B id

  9. 9

    Show Name Instead of ID from Different Table

  10. 10

    Take different names from the same column using two different ID's from other table

  11. 11

    display data from two table by matching id codeigniter

  12. 12

    How to count the number of occurrences of an ID from a different table

  13. 13

    update all values from different table that has same id

  14. 14

    Get a data from a different table using id

  15. 15

    Joining table with range ID matching

  16. 16

    How to order data with matching ID from another table using linq?

  17. 17

    Matching fighters from a single table

  18. 18

    ORDER BY # of rows with same option ID from different table

  19. 19

    Select from a table values that have at least one row matching different requirements

  20. 20

    MySQLi select from two table with limit

  21. 21

    Need Info from different id on the same table Laravel

  22. 22

    mysqli query from multiple table

  23. 23

    Iterating over all rows with the same id and find matching values in a different table

  24. 24

    mySQLi / PHP select row with highest index/id from all matching rows

  25. 25

    How to choose mysqli table id number from dropdown menu and output select values from that row

  26. 26

    Update Table by Matching Invoice ID

  27. 27

    Formatting mysqli output table with different functionalities

  28. 28

    Mysql : select from five different table where matching only one column based on a date or between dates

  29. 29

    Selecting Matching values from three different table and combining them in one table in Oracle

HotTag

Archive