【发布时间】:2015-10-19 18:06:21
【问题描述】:
我有一个表格,可以将调查结果显示到网页中。目前,当用户单击“查看此处”时,它会将他们带到该 ID 的单独条目。单击它时,我希望它还显示其他结果(也是来自同一数据库的部分结果)。
知道我是怎么做到的吗?澄清一下,在单击 ID 以挑出该条目之前,它不应该显示 - 否则它会一个接一个地完整显示它们。
<?php
try {
$handler = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo $e->getMessage();
die();
}
class guestquestionnaireEntry {
public $id, $date_submitted,
$entry;
public function __construct()
{
$this->entry = "
<table border='1' align='center'>
<tr class='tablelist' style='font-size: 8pt;' ><td width='5%' colspan='2'>{$this->ID}</td><td width='40%' colspan='2'><b>Date Received: </b>{$this->date_submitted}</td><td width='45%' colspan='2'>{$this->name}</td><td width='10%'><a href=\"?ID={$this->ID}\">View here</a> </td></tr>
</table>
";
}
}
SELECT DATE_FORMAT(date_submitted, '%m/%d/%Y') AS date_submitted FROM guestquestionnaire
// Checks if the submitted is a number. If so, isolates the ID and adds "where" clause
$id = (!empty($_GET['ID']) && is_numeric($_GET['ID']))? " where ID = '".$_GET['ID']."'" : "";
// Add the $id to the end of the string
// A single call would be SELECT * FROM guestquestionnaire where ID = '1'
$query = $handler->query("SELECT * FROM guestquestionnaire{$id}");
$query->setFetchMode(PDO::FETCH_CLASS, 'guestquestionnaireEntry');
while($r = $query->fetch()) {
echo $r->entry, '<br>';
}
?>
单击“查看此处”后我想显示的其他代码(因此当显示单个条目时):
class guestquestionnaireEntry {
public $id, $date_submitted, $choice, $expectations, $res, $res_information, $res_staff, $further_comments1,
$entry;
public function __construct()
{
$this->entry = "
<tr style='font-size: 8pt;'><td width='60%'><a href=\"?ID={$this->ID}\">ID</a> </td><td width='40%' colspan='2'>{$this->date_submitted}</td></tr>
<tr style='text-align: left; font:arial;'><td><h3>Date Submitted: {$this->date_submitted}</h3></td></tr>
<table border='1' align='center'>
<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Prior to Arrival</td></tr>
<tr style='font-size: 8pt;'><td width='60%'>What made you choose us for your recent trip? </td><td width='40%' colspan='2'>{$this->choice}</td></tr>
<tr style='font-size: 8pt;'><td>Did we meet your expectations as advertised? If no, please state why: </td><td width='40%' colspan='2'>{$this->expectations}</td></tr>
<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'><td colspan='3'>Making your Reservation</td></tr><BR>
<tr style='font-size: 8pt;'><td>Ease of making your reservation: </td><td width='40%'>$img</td><td width='5%'>{$this->res}</td></tr><BR>
<tr style='font-size: 8pt;'><td>Hotel information offered: </td><td width='40%'>$img2</td><td width='5%'>{$this->res_information}</td></tr><BR>
<tr style='font-size: 8pt;'><td>Warmth and friendliness of staff: </td><td width='40%'>$img3</td><td width='5%'>{$this->res_staff}</td></tr><BR>
<tr style='font-size: 8pt;'><td colspan='3'>Further Comments: </BR></BR>{$this->further_comments1}</td></tr>
<BR>
</table>
<BR>
<p>Back to List</p>
";
【问题讨论】:
-
一切顺利吗?您从未提及您最初尝试做的事情是否成功