I have two tables, table A is a commodity table, table B is the message table is the user's comments on the product,
A table ID (self-increment ID) name (product name) money (commodity price) B table ID (self-increment ID) content (message content) PID (corresponding Product ID) UID (user ID)
Product ID Product Name Commodity price message number
xxx xxx xxx xxx
xxx xxx xxx xxx
< 1 2 3 4 5 6 >
To traverse out and display the page, the main is how the data tables are correlated to get the data and then form a new two-dimensional array.
Reply to discussion (solution)
Select a.ID as aid,a.name as Aname,a.money as amoney,b.id as bid from TableB as B left joins table as a on b.pid=a.id where Condition ORDER BY Time DESC limit 0,10//per page 10 article, Pagenow page
This is already a two-dimensional array.
Select A.*,ifnull (b.c,0) from a LEFT join (select Pid,count (0) c from B group by PID) b to a.ID = b.pid ORDER BY a.id Desc L Imit 0, 10;
Thank you, everyone's enthusiastic answer