include_once里面的函数不起作用

Inside a function I need to include a file. The file I need to include contains a query. The result of the included file is

<?php 
$list = $kenmerk_sql->fetch_assoc();

How should I make the include work? The way I do it now does not include the file.

function SelectTime($veld_uur,$veld_min,$naam,$startend,$selected=0)
{
include_once('./includes/getkenmerk.php');
$kenmerk = $list['bk_boekingen_kenmerk'];
Global $_POST;

$ret = "<select name='".$naam."'>
<option value='#' selected>Kies tijd</option>
<option value='#' disabled>############</option>
";

$qry = "
                    SELECT
                        bk_tijden_id,
                        bk_tijden_titel_naam,
                        bk_tijden.bk_tijden_v".$startend."
                    FROM
                        bk_tijden
                    INNER JOIN
                        bk_tijden_titel
                    ON
                        bk_tijden.bk_tijden_titel_id=bk_tijden_titel.bk_tijden_titel_id
                    WHERE
                        bk_boeking_id=?
                    ORDER BY
                        bk_tijden.bk_tijden_v".$startend.",
                        bk_tijden_titel.bk_tijden_titel_naam
                    ASC";
    if(!$tijden_stmt = $connection->prepare($qry)){
    echo 'Fout in query: '.$connection->error;
    } else {
    $tijden_stmt->bind_param('i', $kenmerk);
    $tijden_stmt->execute();
    $tijden_sql = $tijden_stmt->get_result();
    }
    while($tijden_dienst = $tijden_sql->fetch_assoc()){

    $ret .= "<option value='".$tijden_dienst['bk_tijden_id']."' ".(($tijden_dienst['bk_tijden_id'] == $selected) ? "selected" : "").">".$tijden_dienst['bk_tijden_titel_naam']." (".date('H:i',$tijden_dienst['bk_tijden_v'.$startend]).")</option>
";
    }
$tijden_stmt->close();  

$ret .= "
</select>";

    return $ret;
}

You include could be simply loaded earlier, then content was loaded in script, but not in your calling place.

If you call include then you will add content everytime. If you call include_once, will be loaded only once - rest of time, this will return null.

One of solution is to have defined function/class that will hold your data, you want.

Other solution is to have

<?php
return $kenmerk_sql->fetch_assoc();

and in you function:

$list = include( __DIR__ . '/includes/getkenmerk.php');

This way, you can always include you data, like script.

I think you can try require() instead of include.