Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用loop显示单个医生下的所有患者_Php_Mysql_Loops - Fatal编程技术网

Php 使用loop显示单个医生下的所有患者

Php 使用loop显示单个医生下的所有患者,php,mysql,loops,Php,Mysql,Loops,这是我第一次来这里,我需要你的忠告。我正在用php编写一个系统,在这个系统中,注册患者可以预约医生(也注册了)。到目前为止,我已经做了我想要的,但现在我被卡住了 在医生的个人资料页面上,我放置了一个“查看预约”页面(该页面显示了为该医生预订的预约)。我甚至还处理过医生看到他/她有“新预约”的通知(在mysql查询中使用count) 现在,我的问题是,如果那个医生不止一次预约怎么办?我想使用循环来呈现数据,这样他/她就可以在一个页面中同时看到所有内容 我需要一些指导 这是后端 <?php r

这是我第一次来这里,我需要你的忠告。我正在用php编写一个系统,在这个系统中,注册患者可以预约医生(也注册了)。到目前为止,我已经做了我想要的,但现在我被卡住了

在医生的个人资料页面上,我放置了一个“查看预约”页面(该页面显示了为该医生预订的预约)。我甚至还处理过医生看到他/她有“新预约”的通知(在mysql查询中使用count)

现在,我的问题是,如果那个医生不止一次预约怎么办?我想使用循环来呈现数据,这样他/她就可以在一个页面中同时看到所有内容

我需要一些指导

这是后端

<?php
require_once '../inc/connect.php'; //my database connection, which also holds the functions file
if(!$doctor->is_loggedin())
{
$doctor->redirect('index.php');
}
// Getting the doctor id
$dct_id = $_SESSION['dct_session'];

//If need, further actions can be done using this query
$stmt = $DB_con->prepare("SELECT * FROM dct WHERE dct_id=:dct_id");
$stmt->execute(array(":dct_id"=>$dct_id));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);

//this part is for viewing the appointments
$aptid=$_GET['apt_id'];
$stmt2=$DB_con->prepare("SELECT COUNT(dct_id) as aptid FROM apt WHERE dct_id=:aptid");
$stmt2->execute(array(":aptid"=>$aptid));
$aptRow=$stmt2->fetch(PDO::FETCH_ASSOC);
$newApt=$aptRow['aptid'];

if($newApt>0)
{ ?>

<div class="alert alert-info">You have <?php print ($newApt) ?> New Appointment! <br>
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#vwApt">View Appointment</button>
</div>

<?php }
else{ ?>

<div class="alert alert-warning">You have <?php print($newApt); ?> appointments!!</div>

<?php
}

?>

你有新的约会
查看预约 你有约会!!
请注意“模式”,我希望约会详细信息显示在模式框中。 我是一个初学者,使用互联网和一些教程,做了很多工作,但我真的需要指导

数据库中有一个“约会”表,其中包含“医生id”和“患者id”的外键,所以,若我需要从多个表中获取数据,我可以这样做。预约表包含患者姓名、患者详细信息、预约时间/日期和确认/拒绝字段

我希望我能详细解释这个问题

/*编辑*/

这就是我最终用来获取所需的代码。我创建了函数并在视图中使用

<?php
$apts=$this->db->prepare($query);
$apts -> execute();

if($apts->rowCount() > 0)
{
while($row=$apts->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="modal-body">
<table class="table table-bordered table-responsive">
<tbody>
<tr>
<td><?php echo $row['ptnt_fname']; ?></td>
<td><?php echo $row['ptnt_ds']; ?></td>
<td><?php echo $row['apt_day']; ?></td>
<td><?php echo $row['apt_time']; ?></td>
<td><button type="button" name="confirm" class="btn btn-info btn-sm"></button></td>
</tr>
</tbody>
</table>
</div>
<?php
}
?>
<?php
}
?>

这就是我用来称呼这个查询的部分

<?php
$query = "SELECT * FROM apt WHERE dct_id='$aptid'";
$doctor->viewApt($query);
?>
使用

将代码放入try块中。在来这里之前用谷歌搜索一下
向下滚动到底部PDO代码在那里

我们将使用此表作为示例,我们将获取属于供应商1的项目

$sth = $conn -> prepare("select * from items where vendor_id = 1");
$sth -> execute();
$results = $sth -> fetchAll();
会产生这个

+----+---------+---------------------+-----------+
| id | name    | date                | vendor_id |
+----+---------+---------------------+-----------+
|  1 | apples  | 2015-08-19 11:27:27 |         1 |
|  2 | ornages | 2015-08-19 11:27:36 |         1 |
|  4 | bananas | 2015-08-19 11:27:41 |         1 |
+----+---------+---------------------+-----------+
获取每个选定供应商的商品数量

echo count($results); // 3
现在让我们遍历结果并显示项目名称

$html = '<ul>';
foreach ($result as $key => $result) {
    $html .= '<li>'.$result['name'] .'</li>' ;
}
$html .='</ul>';

希望这有帮助。

我得试试:)我可能做错了,因为这对我不起作用。我想。。echo$apt->time;这里的时间代表表中的列,对吗?我在“视图区域”中编写了此代码,使其正常工作。我编写的代码从表中获取患者姓名,而不是单独显示。你看,如果两个病人与同一位医生预约,两个病人的名字都显示在一列中。否则,从表中选择(全部*)以显示新约会,此时仅显示1。我不知道该如何排序。@Rafique,我用一个表示例和代码更新了代码。
$html = '<ul>';
foreach ($result as $key => $result) {
    $html .= '<li>'.$result['name'] .'</li>' ;
}
$html .='</ul>';
. apples
. ornages
. bananas