开发者

PHP, select a random row from a mysql table which haven't been selected yet!

Ok, I have 3 tables;

'bu_blogs' contains blogs which have a unique blog_id.

'bu_sites' contains sites which have a unique site_id.

'bu_blogs_done' contains id, blog_id and site_id. A new row is added to this table every time a site_id is submitted to a blog_id.

What I 开发者_如何学Pythonwant to do is SELECT 2 random rows from 'bu_blogs' where a field in 'bu_blogs_done' for the particular blog_id and site_id does not exist, i.e it haven't been submitted to that blog_id yet.

Thanks

  • Stian


If your table isn't too big (e.g. approx 100 rows), you can use something like this simple example for the random part:

SELECT * FROM bu_blogs ORDER BY RAND() LIMIT 2

Then it's just a case of adding a WHERE clause to filter out the ones that exist in bu_blogs_done.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜