MYSQL结果不显示所有记录

I have a simple script here just to extract the record from mysql from the 2 date range. It is weird it just show 4 records while there is 6 records, I did not set any limit to the records. Can anyone help me out?

Try selecting from:- 1st February till 27th February

Here is my testing site: http://iamawesome.xyz/track/review.php

enter image description here

Here is my code:-

$done = 0;
function displayTable($results) {
    $total_result = count($results);
    echo $total_result." results found.";
    for($x = 1; $x <= $total_result; $x++) {
        //echo "<tr><td>$allresult['id'][$x]</td>";
        echo "<tr><td>".$results['date'][$x]."</td>";
        echo "<td>".$results['url'][$x]."</td>";
        echo "<td>".$results['clickid'][$x]."</td>";
        echo "<td>".$results['code'][$x]."</td></tr>";
    }
}

if (isset($_POST['sub'])) {

$datefrom = $_POST['fromdatetime'];
$dateto = $_POST['todatetime'];

if ($datefrom == "From" || $datefrom == "" && $dateto == "To" || $dateto == "") {
    echo "ERROR! No date/time selected";
}
else {
    /* create a prepared statement */
    $stmt = mysqli_prepare($mysqli, "SELECT * FROM data WHERE date_data between (?) AND (?)");

    /* bind parameters for markers */
    mysqli_stmt_bind_param($stmt, "ss", $datefrom, $dateto);

    /* execute query */
    mysqli_stmt_execute($stmt);

    /* bind result variables */
    mysqli_stmt_bind_result($stmt, $resultid, $resulturl, $resultdate, $resultclickid, $resultcode);

    $resultcount = 0;
    $allresult = array();

    /* fetch value */
    while (mysqli_stmt_fetch($stmt)) {
       //$allresult['id'][$resultcount] =  $resultid;
       $allresult['url'][$resultcount] =  $resulturl;
       $allresult['date'][$resultcount] =  $resultdate;
       $allresult['clickid'][$resultcount] =  $resultclickid;
       $allresult['code'][$resultcount] =  $resultcode;
       $resultcount++;
    }

    /* close statement */
    mysqli_stmt_close($stmt);


/* close connection */
mysqli_close($mysqli);
$done = 1;
}
}
?>

<style>
.searchbox {
border-radius: 20px; 20px; 20px; 20px;
-moz-border-radius: 20px; 20px; 20px; 20px;
-webkit-border-radius: 20px; 20px; 20px; 20px;
border: 2px solid #58ACFA;
}
</style>

<div class="searchbox">

<form action="review.php" method="post" style="margin-left:20px; padding-top:10px;">
<input id="fromdatetime" name="fromdatetime" type="text" placeholder="From" readonly> - <input id="todatetime" name="todatetime" type="text" placeholder="To" readonly>
<input type="submit" name="sub" value="Search" id="btnreview">
</form>
</div>
<br><br>
<?php
if ($done == 1) {
?>
<div class="searchbox">
<table border="1" width="100%" cellspacing="100%">
<tr>
<td><b>Date/Time</b></td>
<td><b>From URL</b></td>
<td><b>ClickID</b></td>
<td><b>Affiliate Code</b></td>
</tr>
<?php
displayTable($allresult);   
}
?>
</table>

The problem is that you are counting the first array. You currently have a multidimensional-array, and you're only counting how many arrays the first array has.

Because you store 4 different values into the array here

$allresult['url'][$resultcount] =  $resulturl;
$allresult['date'][$resultcount] =  $resultdate;
$allresult['clickid'][$resultcount] =  $resultclickid;
$allresult['code'][$resultcount] =  $resultcode;

when you then do count($allresult), it would output 4, because $allresult contains 4 sub-arrays, url, date, clickid and code.

You then use a for-loop for outputting the array in your displayTable function. For one thing, you start counting at 1 (while arrays start with the index 0), but more importantly, the count here is only 4, because the first-tier array contains 4 sub-arrays (as discussed above).

I would rewrite the function using a foreach-loop instead, as that's more suitable for looping through arrays. However, you can just change so that the count function counts through one of the sub-arrays instead, by changing your function from

function displayTable($results) {
    $total_result = count($results); // Outputs static 4, generated in the while-loop
    echo $total_result." results found.";

    for($x = 1; $x <= $total_result; $x++) {
        // continue here...

to

function displayTable($results) {
    $total_result = count($results['url']); // Actual counts of instances found from the query
    echo $total_result." results found.";

    for($x = 0; $x < $total_result; $x++) {
        // continue here...

What essentially was changed here was x = 1; $x <= $total_result to $x = 0; $x < $total_result and, most importantly, from $total_result = count($results); to $total_result = count($results['url']);.

Update your query

SELECT * FROM data WHERE date_data between (?) AND (?)

With

SELECT * FROM data WHERE DATE(date_data) between (?) AND (?)

it might work. Supposed that your first parameter date is lower than second parameter date