Ask the php array as the mysql Query condition wherexxinarray, how to deal with the original thinking to split the array $ mermerid, determine the length to different variables, and determine the number of variables, then write the mysql query below. it may be a bit difficult. could you please ask if you have any good methods? thank you!
---------------------------------------------
$ Customerid:
Array (size = 2)
0 => string '5' (length = 1)
1 => string '14' (length = 2)
----------------------------------------------
$ Customer-> where ("id in". $ customerid)-> count (); // This means that, of course, it is incorrect to put the array directly here.
Reply to discussion (solution)
Because count is counted, the mysql statement below should be one. It is not good to loop through one query.
Foreach ($ customerid as & $ value ){
$ Count = $ customer-> where ("id in". "($ value)")-> count ();
$ Arrcount [] = $ count;
}
$ Count = 0;
Foreach ($ arrcount as & $ value ){
$ Count = $ count + $ value;
}
Solved, and new problems emerged.
How to control, different conditions, (display the first 10 Records)
For example
Where ("id in". (3) has 2
Where ("id in". (2) has 1
Actually, what products are added to each user's favorites. A user may add multiple favorites.
I want to display the first 10 items they have summarized. I do not know how many times they have been combined for query, and the number of times they have been recycled is very troublesome.
Is it best to change the table structure?
In the product table, add a userid? Can a single user add different products to their favorites? It seems that this design works.
The first problem is that if you want to query a single id, you can directly use id = xx, there is no need to use in
If you want to query multiple IDs, combine the array with the implode function into a string in the format of id in (1, 2, 3 ).
The final problem is that if you want to output the user list and output the first 10 favorites of each user, you need to consider caching
Every cool