Php judgment statement

Source: Internet
Author: User
Php judgment statement
$ Pubdate = $ dsql-> GetOne ("select pubdate from article where writer = '". $ writer. "'Order by id desc limit 1"); if (time ()-$ pubdate ['pubdate']) <(3600*24) {ShowMsg ("sorry, one member can only send one article per day! ","-1 "," 0 ", 5000); exit ;}


In the above judgment, one member can only submit one document within one day. if you want to modify it, you can submit three documents. what should you do?


Reply to discussion (solution)

$ Pubdate = $ dsql-> GetOne ("select pubdate, writer, count (pubdate) as total from article where writer = '". $ writer. "'and pubdate <". strtotime ("-1 day "). "limit 3 ");
If ($ pubdate ['total']) = 3 ){
ShowMsg ("Sorry, one member can only send one article every day! ","-1 "," 0 ", 5000 );
Exit;
}


Mysql queries the number of articles submitted in a day. if the number is greater than or equal to 3, it cannot be submitted.

$ Pubdate = $ dsql-> GetOne ("select pubdate, writer, count (pubdate) as total from article where writer = '". $ writer. "'and pubdate <". strtotime ("-1 day "). "limit 3 ");
If ($ pubdate ['total']) = 3 ){
ShowMsg ("Sorry, one member can only send one article every day! ","-1 "," 0 ", 5000 );
Exit;
}


Mysql queries the number of articles submitted in a day. if the number is greater than or equal to 3, it cannot be submitted.

Mysql cannot run. Please check.
In addition: if ($ pubdate ['total']) = 3) should be if ($ pubdate ['total']) = 3?
Database field:
Database name (article)
Member Name (writer)
Pubdate)

The original code is changed

$ N = 1; // The number of entries you specify $ pubdate = $ dsql-> GetOne ("select count (*) as cnt from article where FROM_UNIXTIME (pubdate, '% Y % m % d') = DATE_FORMAT (now (),' % Y % m % d') and writer = '". $ writer. "'Order by id desc limit 1"); if ($ pubdate ['pubdate']> $ n) {ShowMsg ("Sorry, one member can only send $ n articles per day! ","-1 "," 0 ", 5000); exit ;}

I still learned from the moderators.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.