douche5961 2019-02-02 09:55
浏览 99
已采纳

phpMyAdmin DATE变量到SELECT命令 - 致命错误:未捕获的ArgumentCountError

I'm new here and I learn PHP and SQL connection. I want to list from the SQL database the room numbers what are not reserved. I create 2 tables ( rooms and reservation ) with fill some exapmles.

Step 1

If I put direct DATE for the "end reservation" DATE("2019-03-11") like this work well and listed the room numbers

function reserv3()
{
    include "config.php";
    $html = "";
    $sql = 'SELECT roomnr , reserv_start FROM rooms LEFT OUTER JOIN reservation ON reservation.room_id = rooms.room_id AND DATE(reservation.reserv_start)  >= DATE("2019-03-11")';
    $result = mysqli_query($conn, $sql);
    while( $sor = mysqli_fetch_array($result) )
        $html .= "<DIV>".$sor['roomnr'].", ".$sor['reserv_start']."</DIV>";
    return $html;
}

Step 2

I want to replace the fixed DATE("2019-03-11") to a variable.

$today = DATE("2019-03-11");
function reserv3($today)
{
    include "config.php";
    $html = "";
    $sql = 'SELECT roomnr , reserv_start FROM rooms LEFT OUTER JOIN reservation ON reservation.room_id = rooms.room_id AND DATE(reservation.reserv_start)  >= '.$today;     
    $result = mysqli_query($conn, $sql);
    while( $sor = mysqli_fetch_array($result) )
        $html .= "<DIV>".$sor['roomnr'].", ".$sor['reserv_start']."</DIV>";
    return $html;
}

I have in Step 2 the Fatal error Fatal error: Uncaught ArgumentCountError: Too few arguments to function reserv3(), 0 passed in

Can you help me how can I put variable to this command ? Thank you

  • 写回答

1条回答 默认 最新

  • doujiao1814 2019-02-02 11:46
    关注

    Something is wrong in your code. PHP date() generates the date. If you want the current date write date ('Y-m-d') for date and date ('Y-m-d H: i: s)' for the date and time. In mysql if the field is the date type you do not have to use the mysql date() function to compare. Only if it is of the datetime type use the date() function to extract the date.

    <?php
    include "config.php";
    
    $today = DATE('Y-m-d');
    
    function reserv3($today)
    {
        global $conn;
    
        $sql = 'SELECT t1.roomnr , t2.reserv_end FROM reservation as t2 LEFT JOIN rooms as t1 ON t2.room_id = 
                   t1.room_id where t2.reserv_end <= '.$today;     
        $result = mysqli_query($conn, $sql);
    
        if(mysqli_num_rows($result)>0){
         // do something
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配