简体   繁体   English

如何显示表中的固定条目数

[英]How to display fixed number of entries from table

I have a table with 100+ entries, I want to display fixed number of entries from this table randomly. 我有一个包含100多个条目的表,我想随机显示该表中固定数量的条目。

I am using the query below. 我正在使用下面的查询。

SELECT * FROM Table1 WHERE active='1' AND id NOT IN 
(SELECT ad_id FROM Table1_logs WHERE uid='$username') ORDER BY RAND() LIMIT 5

Table1 contain all the entries, Table1_logs contains the entries which have been utilized by users today. Table1包含所有条目, Table1_logs包含当今用户已使用的条目。

Problem: 问题:

I need to pick 5 entries daily for each users and should not exceed that amount. 我需要每天为每个用户选择5个条目,并且不应超过该数量。 when a user utilizes one entry and it is saved in logs, query picks again 5 entries and it remains 5 all the time. 当用户使用一个条目并将其保存在日志中时,查询会再次选择5个条目,并且始终保持5 5条目。

What I want to acheieve: 我要实现的目标:

When a user utilizes one entry, it count should decrease. 当用户使用一个条目时,它的数量应减少。 He should be able to see only 5 entries daily. 他每天应该只能看到5个条目。

You should add a new field to table1 "utilizationCount" . 您应该向table1“ utilizationCount”添加一个新字段。 When a link is utilized, you increase the value by one. 使用链接时,将值增加一。 And in the query, you should order by this field: " order by utilizationCount asc limit 5" . 并且在查询中,您应按以下字段进行排序:“按applicationCount asc limit 5排序”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM