开发者

show daily Sentence by php and get from database

how i can show daily Sentence in site by get Non-recurring value from database ?

my database have more than 365 Sentence

my database table's Structure is :

id,text

i think i should crate a show in my table's Structure that Default value is 0 and when Sentence show开发者_JS百科ed in site show = 1

this is true ?


Yes you can add an extra column and get record using query like this:

select text from sentences where show=0;

EDIT:

You can get random record from table as well.

Example:

SELECT * FROM `sentences` WHERE show=0 ORDER BY RAND() LIMIT 0,1;

But this method is slow with large tables. See more details in following article:

  • SQL to Select a random row from a database table


You could also reduce the number of sentences in your database to 366 and run this query:

SELECT * FROM sentences WHERE id = DAYOFYEAR(NOW())

Of course, this means you need to keep 366 sentences with ID numbers 1-366, else it won't work.


either yes (create that show column) or just show them in sequence, today is day 1, show sentence id 1, tomorrow sentence 2 etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜