使用MySQL和PHP通过format_date计算行数

时间:2015-08-21 12:23:48

标签: php mysql

我想计算今天的投票数,但没有分钟和秒数。 我的意图是将今天的表格Voteslist和VoteID($ _ GET)的投票数等于“2”。

select_information = mysql_query("SELECT * FROM `Vote` WHERE `VoteID` = '$VoteID';");
        $take = mysql_fetch_array($select_information);
        $createdBy = $take["Username"];
        $select_last_vote = mysql_query("SELECT `Date` FROM `voteslist` WHERE `IP` = '$ip' AND `VoteID` = '$VoteID' order by `Date` DESC LIMIT 1;");
        $select_last_vote = mysql_fetch_array($select_last_vote);
        $dbdate = $select_last_vote["Date"];
        $takeResult = mysql_query("SELECT DATE_FORMAT(STR_TO_DATE('$dbdate', '%d/%m/%Y' ), '%d/%m/%Y') as Date ;");
        $Result_date = mysql_fetch_array($takeResult);
        $result_date = $Result_date["Date"];
        $today = date("d/m/Y");
        $thanks_to = $createdBy;

        /* HERE IS MY PROBLEM */
        $today_voting_query = mysql_query("SELECT DATE_FORMAT(STR_TO_DATE('$dbdate', '%d/%m/%Y' ), '%d/%m/%Y') as Date, COUNT(ID) AS countID FROM `voteslist` WHERE `VoteID` = '$VoteID' AND `Date` = '$result_date';");
        $today_voting = mysql_fetch_array($today_voting_query);
        $today_voting = $today_voting[1]; //OUTPUT: 0 , and I have 2 rows..
        $total_voting_q = mysql_query("SELECT COUNT(`ID`) FROM `Vote` WHERE `VoteID` = '$VoteID';");
        $total_voting_f = mysql_fetch_array($total_voting_q);
        $total_voting = $total_voting_f[0];
        if($today_voting == 0)
        {
            $today_voting = "No new votes today";
        }

        if(strlen($InstaCredit) > 3)
        {
            $thanks_to = "<a class='thanks-to'>$thanks_to</a>";
        }
#       SELECT `Date` FROM `Vote` WHERE `IP` = '$ip' AND `VoteID` = '$VoteID' order by `Date` DESC LIMIT 1

        //now compare your dates
        if($result_date == $today)
        {
            echo "<span class='thanks-for-voting voted'>
            You can't vote again to <strong>{$thanks_to}</strong>
            </span><br />
            <span class='note-vote voted'>You can vote only one time in 24hours</span>";
        }
        else {
        $new_vote = mysql_query("INSERT INTO `voteslist` (`ID`, `Username`, `IP`, `VoteID`, `Date`) VALUES (NULL, '".$_SESSION['username']."', '$ip', '$VoteID', '$date');");
            echo "
            <span class='thanks-for-voting'>
            Thanks about vote to<strong>{$thanks_to}</strong>!
            </span>
            ";
        }
?>
    <div class="statics">
    <span id="static-title">Static of <?php echo $thanks_to; ?></span><hr />
    <span id="static-q">Today votes:</span><span id="static-a"><?php echo $today_voting; ?></span><br />
    <span id="static-q">Total votes:</span><span id="static-a"><?php echo $total_voting; ?></span><br />
    </div>

也许可以帮助你理解我:

How to count rows by date using MySQL and PHP

Select date from my db without seconds using PHP MySql

0 个答案:

没有答案