繁体   English   中英

我想从一个php文件中获取包含mysql查询的变量,并编写将在另一个php文件中打印查询内容的循环

[英]I want to take the variable that contains a mysql query from one php file, and write the loop that will print the query contents in another php file

我是一个初学者,试图制作一个从数据库中检索预定时间表的网页。 在一个php文件中,我有一个类,该类具有使用SELECT语句创建查询的功能,以下是该功能

public function getDTodayScheduleDB(){

             $session=Modulator::getSession();
             $session->start();
             $currentdrID=$_SESSION['userID'];

             $todayDate = date("Y/m/d");

             $getTSchedule = "SELECT time, user.name FROM reservation FULL JOIN user ON childID = user.ID AND doctorID = '$currentdrID'  AND date = '$todayDate'";
             $result = Modulator::getDb()->query($getTSchedule); 
             return $result;
        }

我不确定这是否是正确的方法,但是当我尝试使用Google搜索时会读到它。 $ result变量在php文件中返回并像这样使用

<?php

                include realpath($_SERVER['DOCUMENT_ROOT'] . '/Classes/Models/DoctorModel.php');
                $scheduleResult = DoctorModel::getDTodayScheduleDB();
                while($row = mysqli_fetch_assoc($scheduleResult)){
                    $appTime = $row['time'];
                    $childName = $row['name'];





                    echo"<tr>";
                    echo"<td>".$appTime."</td>";
                    echo"<td>".$childName."</td>";
                    echo"</tr>";
                }
             ?>

但是我不知道为什么它不起作用,尽管我在其他地方测试了该查询,并且它起作用了,所以他的问题是变量从函数传递到我猜的另一页。

使用::运算符,您将调用非静态(即实例方法)函数,就好像它是静态函数一样。 假设您的getDTodayScheduleDB在DoctorModel类内,则必须通过以下方式进行定义:

public static function getDTodayScheduleDB(){
   //your code here 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM