4天后阻止请求

时间:2016-02-27 12:47:04

标签: php

我只需要有db结构和逻辑的帮助:代码部分我将自己做

我正在发送一些请求发送系统,用户可以在第二天发送最多4个requet,之后他们将能够在第二天发送请求

下面是我正在使用的数据库结构

Db结构:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_appb);

    Intent i = getIntent();
    Log.w("ID", "Called id:" + i.getIntExtra("id", -1));

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent i= new Intent();
            returnIntent.putExtra("resultdata", "mydata");
            setResult(Activity.RESULT_OK, i);
            finish();
        }
    });

}

我无法弄清楚它的流动逻辑

请指导我这样做

1 个答案:

答案 0 :(得分:1)

这应该让你开始。在我的例子中,我使用了一个SQL数据库,注意到这些评论。逻辑工作,您只需要将值拉出并保存到数据库中。

<?php
$userid = 1;
// get the current saved data from the database by user, like below
// SELECT * FROM `requests` WHERE `userid` = '$userid'
// put database data into variables like below, example only
$lastrequestsent = $db->LastRequestSent;
$requestcount = $db->requestCount;

// if it is a new day, reset requestcount to 0, otherwise if not a new day, keep value
$requestcount = (date('Y-m-d') === date('Y-m-d',strtotime($lastrequestsent))) ? $requestcount : 0;

// if requestcount is less than 3
if ($requestcount < 3) {
  $lastrequestsent = date('Y-m-d'); // assigns the current date to lastrequestsent 
  $requestcount++; // increments requestcount by 1
  echo "You can still request today.";
  // update data into database
  // UPDATE `requests` WHERE `userid` = '$userid' SET `lastrequestsent` = '$lastrequestsent', `requestcount` = '$requestcount'
}
else {
  echo "You cannot request anymore today.";
}
?>