开发者

How to fix mysql SELECT query from always stopping at a specific record?

I'm trying to make a php tool that will get the users registered between specific dates. However, I'm running into a strange issue. The query doesn't seem to recognize all of the records in the table. Let me explain.

Here's the php code:

    function getRegistrations($startDate,$endDate) {
    //echo $startDate;
    //echo $endDate;
    $startDate = date('Y-m-d H:i:s',$startDate);
    $endDate = date('Y-m-d H:i:s',$endDate);
    $query = "SELECT * FROM database.user WHERE created_date>='".$startDate."' AND created_date<='".$endDate."';";
    $result = mysql_query($query);
    $data = array();
    $data['query'] = $query;
    $data['content'] = array();
    if($result) {
        $data['status'] = 1;
        $data['message'] = "Success";
    }
    $count = 0;
    $data['num_rows'] = mysql_num_rows($result);
    while ($row = mysql_fetch_assoc($result)) {
        $data['content'][开发者_C百科$row['user_id']] = $row;
        $count++;
    }
    $data['count'] = $count;
    echo json_encode($data);
}

When I run the query in the mysql workbench, it works just fine. However, when I'm running it through php, it seems to ignore every record after a certain one. I can see all the records up to user_id=243, and then it ends. num_rows and count are still equal, and they're equal to the length of content. However, if I run the query directly from the mysql workbench, I can see that it should be much higher. Also, it's always stopping at the same record, regardless of the dates. If I choose an early start date, then it might return 50 records, but it still stops at the same one.

Does anyone have any ideas? Although I'm pretty new to MySQL, I haven't been able to find anyone with a similar problem.

Thanks in advance!


delete that one particular row. simple as that. reinsert it and see if the problem persists.


mysql_query() says query string should not end with a semicolon. Your query should be

$query = "SELECT * FROM database.user WHERE created_date>='".$startDate."' AND created_date<='".$endDate."'"; 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜