开发者

Retrieve articles from array of category ids [duplicate]

This question already has answers here: How to bind an array of strings with mysqli prepared statement? (6 answers) Use an array in a mysqli prepared statement: `WHERE .. IN(..)` query [duplicate] (8 answers) Closed 9 months ago.

I have an array of category i开发者_StackOverflowds and want to retrieve articles from my mysql database with these category ids. What is the best method for this?


mysql_query('SELECT * FROM articles WHERE category_id IN (\''.implode('\'',array_map('mysql_real_escape_string',$categories)).'\')');

Specify how articles are joined to categories if this is not how your db/table setup.


Look here:

  • I have an array of integers, how do I use each one in a mysql query (in php)?

for a safe, parameter-based approach and code sample.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜