I’ve got a query to my MySQL database returning four fields of information from a MySQL table (information), which I then encode for JSON using PHP’s json_encode() function. Two of the fields it returns are “staffMember” and “lineManager”, which return integers that relate to the ID of that person in a (separate) users table.
My query returns the following (in table format):
id is 1
staffMember is 14
lineManager is 12
description is this is a description
etc.. for all the rows.
14 (in the case of the above for example) refers to a row in the users table that would be something like:
id is 14
firstname is dave
secondname is jones
My question is therefore, how can I get the JSON part of the query to return “dave jones” instead of 14? As the info isn’t held in the same table in MySQL.
Use LEFT JOIN in your database request like
where a and b – your table names