【发布时间】:2015-08-25 02:39:52
【问题描述】:
这是我第一次来这里,我希望得到您的建议。我正在用 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);
?>
感谢大家的热心回复和指导。非常感谢。
【问题讨论】: