There is a usr table that stores uid, username
Business table 1, the stored information has the field uid, username
Business table 2, the stored information is only uid,
(Business table 2 has multiple fields The data corresponds to one piece of data in business table 1)
Existing: The query traverses business table 2, the data is an array list, and username needs to be assembled on the list to facilitate front-end display
Method one is that each list is based on uid goes to the usr table of the database to query username;
The second method is to first traverse the query business table 1, use an empty array arr, the key stores uid, the corresponding value stores username, traverse the list, use array_key_exists to determine whether uid is one of the keys in arr , if so, get arr[uid] as username
The second advantage is that it avoids multiple database queries for username, but there is a problem with using the key of an empty array to store uid. If the uid value is very large, such as 10000, Will this involve PHP array memory issues (I don’t know much about this aspect)
I also want to know if there are any other shortcomings in the second method. If so, is there any other better way to deal with it
Linked list query. External link
Just query the linked tables