I'm guessing you've all met the following conditions.
I have two tables, magazine (magazine information) and Subscibe (subscription information), in the Subscibe table I have a magazine_id to be associated with the number in the magazine table
Now I'm going to do a list of browsing subscriptions, which contains a list of the names of the magazines (the Name field of the magazine table), and one way is to use the join to make an association between the two tables, replacing the magazine_id with the name, But this list is a search result, the SQL query statement is a concatenation, if plus join, the concatenation of SQL logic will become a bit more complicated, so it is easy to get a select * from Subscibe where ..., and then put the result set Magazine_ ID to the query will be more simple, and there is another problem is that I do not want to be in my program too many repeated queries, such as the result set of 10 data is about the same magazine_id, I will have more than 9 duplicate query, so I decided to do so
function Magazineinfobyid ($magazine _id) {
Global $db;
Static $magazine _info;
if (!isset ($magazine _info[$magazine _id])) {
$magazine _info[$magazine _id] = $db->getrow (' select * FROM magazine WHERE id = '. $magazine _id);
}
return $magazine _info[$magazine _id];
}
while (...) {
$magazine _info = Magazineinfobyid ($magazine _id);
.....
}
Magazineinfobyid () The static variable $magazine_info becomes a cached form of things, in some cases, can greatly reduce the number of queries, avoid duplicate queries