Include_once function inside doesn't work

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

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

      

How do I get include to work? The way I am doing 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>\n";

$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>\n";
    }
$tijden_stmt->close();  

$ret .= "
</select>";

    return $ret;
}

      

+3


source to share


2 answers


You can load an earlier version, then the content was loaded into the script, but not at your call location.

If you call include

, you will add content every time. If you call include_once

it will only be loaded once - the rest of the time, this will return null.

One solution is to define a specific function / class that will store your data, you want.

Another solution is



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

      

and in your function:

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

      

This way you can always include data like script.

+1


source


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



0


source







All Articles