【发布时间】:2012-12-17 03:14:26
【问题描述】:
请先阅读编辑 2,谢谢!
我一直在开发一个名为“inoffice.php”的页面,该页面显示学生等待被看到和当前被看到的页面视图如下:
现在几乎我刚刚使用上面的同一张表来获取第二张表,但是我添加了一个左连接,以便显示与学生一起工作的辅导员(在本例中为 Dawne)以及学生被录取的时间由辅导员。
项目的那部分非常困难,但我还是能挺过去。现在对我来说困难的部分是这个(这也是我的问题):
1) 除非顾问(或工作人员)单击“开始会话”按钮(不是 php 会话而是学生和辅导员之间的现实生活中的会面)
2) 我怎样才能让第一张桌子(等待)在顾问(工作人员)点击“开始会议”按钮时丢失一个条目。
我的数据库架构如下:
- 用户 - 持有员工凭证
- Waiting - 包含 ID(PK)、anum(这是一个学生 ID 号)、 首先,最后,为什么,cmets,signintime
- couselors - 这包含 ID(PK 和 FK 从等待加入中使用)、counselorname、counselor 开始时间
- cmets - ID(等待中的 PK 和 FK)、评论(辅导员 cmets 大约 varchar 50)
- finish - ID(PK 和 FK 等待),以及辅导员与学生结束时的时间戳
因此,希望通过我提供的信息,有人可以详细说明我应该如何/是否应该使用触发器或事务来完成此操作。或者,如果它是 PHP 的“东西”——因为没有更好的词。
谢谢你, 愤怒
编辑 2:删除旧的不工作代码,用新代码更新帖子并删除过时的屏幕截图!包括更新的一个! :
<php
require('core/init.php');
if(!isset($_SESSION['LoggedIn'])){
die("You must <a href='index.php'><bold>login</bold></a> before you can see that page!");
}
//Begin the select statements
try
{
$query = $dbh->prepare("SELECT * FROM waiting WHERE counselorname IS NULL ");
$query->bindParam(':null', $null);
$query->execute();
$result = $query->fetchall();
}
catch (PDOException $e) {
error_log($e->getMessage());
die($e->getMessage());
}
echo "Return to <a href='login_success.php'><bold>Home Page</bold></a>";
echo "<br />";
echo "Waiting";
echo
"<table border='2'>
<tr>
<th>ID</th>
<th>A Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Why</th>
<th>Comments</th>
<th>Signintime</th>
<th>Staff Member</th>
<th>Click if ready!</th>
</tr>"
;
foreach($result as $row)
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td><a href=Student.php?student=" . $row['anum'] . ">" .$row['anum'] . " </a></td>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "<td>" . $row['why'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "<td>" . $row['signintime'] . "</td>";
echo "
<td> <form action='counselor.php?id=" . $row['id'] . "' method='post' target='_new'>
<select name='namedrop'>
<option value=''>Counselor Name</option>
<option value='Admin-John'>Admin - John</option>
<option value='Admin-Christine'>Admin - Christine</option>
<option value='Admin-Dawne'>Admin - Dawne</option>
<option value='Counselor-Cherie'>Counselor - Cherie</option>
<option value='Counselor-Tootie'>Counselor - Tootie</option>
<option value='Counselor-Debbie'>Counselor - Debbi</option>
<option value='FrontDesk-Delores'>Front Desk - Delores</option>
<option value='FrontDesk-Kiana'>Front Desk - Kiana</option>
</select>
</td>
<td> <input type='submit' name='submit' value='Start Session'></td>
</form> </td>";
}
echo "</tr>";
echo "</table>";
echo "<br />";
echo "<br />";
try
{
$query2 = $dbh->prepare("SELECT * FROM waiting WHERE counselorname is NOT NULL");
$query2->execute();
$result2 = $query2->fetchall();
}
catch (PDOException $e) {
error_log($e->getMessage());
die($e->getMessage());
}
echo "Return to <a href='login_success.php'><bold>Home Page</bold></a>";
echo "<br />";
echo "Being seen";
echo
"<table border='2'>
<tr>
<th>ID</th>
<th>A Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Why</th>
<th>Comments</th>
<th>Signintime</th>
<th>Staff Member</th>
<th>Counselor Start Time</th>
</tr>"
;
foreach($result2 as $row2)
{
echo "<tr>";
echo "<td>" . $row2['id'] . "</td>";
echo "<td><a href=Student.php?student=" . $row2['anum'] . ">" .$row2['anum'] . " </a></td>";
echo "<td>" . $row2['first'] . "</td>";
echo "<td>" . $row2['last'] . "</td>";
echo "<td>" . $row2['why'] . "</td>";
echo "<td>" . $row2['comments'] . "</td>";
echo "<td>" . $row2['signintime'] . "</td>";
echo "<td>" . $row2['counselorname'] . "</td>";
echo "<td>" . $row2['counselor_time'] . "</td>";
}
?>
【问题讨论】:
-
这主要是一个 PHP 的东西。您用来获取这两个表的数据的 SQL 查询是什么?这些必须修改。
-
我会添加一个条件来检查
signintime是否为空白,基于您要显示的两个列表的结果。您还可以检查finish表(假设#5 确实是一个表)。如果您显示您的代码,而不仅仅是屏幕截图,这也会很有帮助。 -
代码已根据要求添加。
标签: php mysql transactions triggers pdo