简化并加快每月每天查询数据库的过程

I have a feeling that this isn't the most effective way to go about obtaining and displaying this information, but I can't seem to find an answer anywhere that directly applies to what I'm doing. I need to query the database for each day of the month and display that information. I need to display every day in the month even if there is no data.

The only way I know how to do this is to query the database for every day. I know querying the database too often slows down the page load time. Should I get the data for the entire month and search through the array instead?

The basic idea of what I am doing:

// DATES OF MONTH ARE IN AN ARRAY CALLED $dates
foreach($dates as $key => $date){
    $getdata = mysqli_query($link, "SELECT * FROM `Data` WHERE section = $section AND type = $typeid AND `date` = $datecomp");
    $info = mysqli_fetch_assoc($getcatdata);
    if(isset($info)){
        // Display info
    }
    else {
        // Display empty div
    }
}

Run a query, which will return you all records within the datarange.

Then in PHP scroll through dates and on each date check if you have any records within the DB query results.

if yes - show them if not - show empty div

Without very much details the PHP would be like that:

$getdata = mysqli_query($link, "SELECT * FROM `Data` WHERE section = $section AND type = $typeid AND `date` BETWEEN $startDate AND $endDate");
$info = mysqli_fetch_assoc($getcatdata);
$dbData = Array(); // this will be an assoc array with dates as keys
foreach($info as $row) {
    $dbData[$row["date"]] = $row;
}

$unixStartDate = strtotime($startDate);
$unixEndDate = strToTime($endDate);
for($i=$unixStartDate; $i<=$unixEndDate; $i=$i+60*60*24) {
    if(array_key_exists(date('Y-m-d', $i), $dbData)){
    // Display info of $dbData[date('Y-m-d', $i)]
    }
    else {
    // Display empty div
    }
}

Note: the code might be slightly different if your date field format is not yyyy-mm-dd.

So, as summary - you have one DB query. It will be faster.