doupingzhi9674 2017-04-23 02:32
浏览 174

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;
}
  • 写回答

2条回答 默认 最新

  • donglue1886 2017-05-15 13:25
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置