我有一个页面,显示我的表单(在网页中)的回复。目前,所有的回复都在一页上,一个接着一个。我希望该页面显示提交的所有日期(date_submitted
)和ID
号码的列表,当点击它时,它会将我们带到具有该特定响应的页面(即完整响应)。如何创建将其带入此记录的链接?
这是该页面的代码:
<?php error_reporting(E_ALL); ?>
<head>
<link rel="stylesheet" type="text/css" href="surveystyle.css" media="all" />
</head>
<body>
<div id="container2">
<div class="logo-header"><img src="images/logo.jpg" alt="" width="205" height="119" /></div>
<h2> Guest Questionnaire Responses </h2>
<?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, $choice, $expectations, $res, $res_information, $res_staff, $further_comments1,
$entry;
public function __construct()
{
$this->entry = "<a href=\"?ID={$this->id}\">ID</a>
<tr style='text-align: left; font:arial;'><td><h3>Date Submitted: {$this->date_submitted}</h3></td></tr>
<BR>
<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 stay? </td>
<td width='40%' colspan='2'>{$this->choice}</td>
</tr>
<tr style='font-size: 8pt;'>
<td>Did our hotel 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>";
}
}
// 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>';
}
?>
</div>
</body>
答案 0 :(得分:0)
您需要在sql中执行<!-- Use whatever here to click on that triggers the ID reload -->
<a href="?ID=<?php echo $this->id; ?>">ID</a>
:
HTML按钮:
// 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');
SQL查询:
// Should be something like this
public function __construct()
{
$this->entry = "
<a href=\"?ID={$this->id}\">ID</a>...etc.
修改强>
{{1}}