I'm going to write a SQL to find all the user arrays, and then the Foreach Loop this array takes the ID to check all of his product data, there is no better way
Reply content:
I'm going to write a SQL to find all the user arrays, and then the Foreach Loop this array takes the ID to check all of his product data, there is no better way
The basic data of a commodity can be cached, especially with large traffic. The less the database goes, the better.
But the user to buy what goods or to go to the database good point is read-write separation
If the user ID has a foreign key, check with the left join.
If you don't have an index, this is the way to go.
The join statement can implement the
This at the same time take out to join, properly indexed, encapsulated into a stored procedure to tune, will be faster, I think if the traffic is large, the two logic apart, the front-end asynchronous take OK
Paging queries, such as 10 per page, get the ID array of the user.
Chaku can be used in (,....).
Of course, if access is frequent, it's best to add the cache
Create view as Select from join creates a views, pay attention to adding indexes, and then query as a table.
Generally speaking, users and products are bound to foreign keys. In this case, use Join (Leftjoin,rightjoin. ) can be taken out all at once. If the foreign key is not bound, then I suggest you may have to redesign the foreign key, after all, the foreign key in the user information update or delete automatically update or delete items.