SQL准备的语句重新调整空的JSON数组

问题描述

当我选择3个单选按钮时,我希望从相应的表中加载下拉列表,因此我声明了变量$choice以保存单选按钮的状态并分配2个新变量{ {1}}设置要从中获取数据的表的名称,另一个$table设置每个表的列名 然后使用准备好的语句连接到mysql DB

$secolumn

然后在前端,当我按下某个单选按钮之一时,我添加了以下脚本 /下拉列表ID sel_curr_name的ID

<?php
include "connect.php";//to connect to the mysql DB
$table ='';
$secolumn ='';
if (isset($_GET["table_cond"])) {
    $choice = $_GET["table_cond"];
    if ($choice == "table_fixe") {
        $table = "cr002t_cours_fixe";
        $secolumn ="CR002_DEV_DIN";
    } elseif ($choice == "table_billets") {
        $table = "cr004t_cours_billet";
        $secolumn = "CR004_DEV_BILLC";
    } elseif ($choice == "table_itqb") {
        $table = "cr005t_cours_intbq_comp";
        $secolumn = "CR005_DEV_COMP";
    } else {
        echo "choose a button";
    }
}

$sql ="SELECT DISTINCT GR027DEVISE,GR027LIB 
        FROM gr027t_devises D,".$table." T 
        WHERE D.GR027DEVISE = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt,$sql)) {
    echo"sql statement failed";
}else {
    mysqli_stmt_bind_param($stmt,"s",$secolumn);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
}
$currency_array=[];
while ($row = mysqli_fetch_assoc($result)) {
    $id = $row['GR027DEVISE'];
    $name = $row['GR027LIB'];
    $currency_array[] =array("id"=>$id,"name"=>$name);
}
echo json_encode(['currency_array'=>$currency_array]);
?>

当我选择按钮中的一个时,我得到一个空数组=>,而在网络选项卡中,我得到了这个{“ currency_array”:[]}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...