猿问

SQL数组var_dump不显示任何内容

我有一些加载工作时间的代码。我的数据库看起来像


id - int(11)

day - varchar(255)

starttime - (time)

endtime - (time)

date - (date)

type - int(1)

我尝试通过以下方式获取数据:


if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

echo "Connected successfully";


function get_all_records($sql){

    global $conn;


    $result = $conn->query($sql);

    $result = [];

    while($row = $result->fetch_assoc()) $result[array_shift($row)] = $row;

    return $result;

}


$sql = "SELECT day, starttime, endtime FROM schedule WHERE type =  ";


$shop_hours = array_merge(

    get_all_records($sql . "0 ORDER BY id"),

    get_all_records($sql . "1 and YEARWEEK('DATE') = '201915'")

);



var_dump ($shop_hours);

?>

仅显示内容已成功连接


有只小跳蛙
浏览 168回答 2
2回答

三国纷争

您正在用一个空数组覆盖结果变量。您应该更改此数组的名称:$result = [];

料青山看我应如是

我在第14行发现了问题而($行= $查询- > FETCH_ASSOC())$结果[array_shift($行)] = $行;&nbsp; &nbsp; <?php&nbsp; &nbsp;&nbsp;$conn = new mysqli($dbhost, $dbusername, $dbpassword, $dbname);if ($conn->connect_error) {&nbsp; &nbsp; die("Connection failed: " . $conn->connect_error);}&nbsp;echo "Connected successfully";function get_all_records($sql){&nbsp; global $conn;&nbsp; $query = $conn->query($sql);&nbsp; $result = [];&nbsp; while($row = $query->fetch_assoc()) $result[array_shift($row)] = $row;&nbsp; return $result;}$sql = "SELECT day, starttime, endtime FROM schedule WHERE type = ";$shop_hours = array_merge(&nbsp; get_all_records($sql . "0 ORDER BY id"),&nbsp; get_all_records($sql . "1 and YEARWEEK('DATE') = '201915'"));var_dump($shop_hours);?>
随时随地看视频慕课网APP
我要回答