Php 如何通过数据库条目创建链接
我有一个页面,显示我表格中的回复(在网页中)。目前,所有的回答都放在一页纸上,一页接一页。我希望页面显示所有提交日期(Php 如何通过数据库条目创建链接,php,database,forms,Php,Database,Forms,我有一个页面,显示我表格中的回复(在网页中)。目前,所有的回答都放在一页纸上,一页接一页。我希望页面显示所有提交日期(date\u submitted)和ID编号的列表,单击该列表后,我们将进入包含该特定响应(即完整响应)的页面。如何创建一个链接,将其带到此记录 这是我在该页面的代码: <?php error_reporting(E_ALL); ?> <head> <link rel="stylesheet" type="text/css" href="surve
date\u 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>
客人问卷回答
您需要在sql中执行where
:
HTML按钮:
<!-- Use whatever here to click on that triggers the ID reload -->
<a href="?ID=<?php echo $this->id; ?>">ID</a>
// 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');
// Should be something like this
public function __construct()
{
$this->entry = "
<a href=\"?ID={$this->id}\">ID</a>...etc.
编辑:
<!-- Use whatever here to click on that triggers the ID reload -->
<a href="?ID=<?php echo $this->id; ?>">ID</a>
// 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');
// Should be something like this
public function __construct()
{
$this->entry = "
<a href=\"?ID={$this->id}\">ID</a>...etc.
//应该是这样的
公共函数构造()
{
$this->entry=”
等
您需要在sql中执行操作,其中
:
HTML按钮:
<!-- Use whatever here to click on that triggers the ID reload -->
<a href="?ID=<?php echo $this->id; ?>">ID</a>
// 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');
// Should be something like this
public function __construct()
{
$this->entry = "
<a href=\"?ID={$this->id}\">ID</a>...etc.
编辑:
<!-- Use whatever here to click on that triggers the ID reload -->
<a href="?ID=<?php echo $this->id; ?>">ID</a>
// 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');
// Should be something like this
public function __construct()
{
$this->entry = "
<a href=\"?ID={$this->id}\">ID</a>...etc.
//应该是这样的
公共函数构造()
{
$this->entry=”
等
谢谢。这与我上面列出的代码在同一页上吗?有点困惑该放在哪里。是的,sql查询会添加行并替换您的行。HTML按钮会放在构造()中的某个地方不过你想把它摆出来。这可能更像是
思想谢谢,但我似乎无法让它工作。你更新的最后一行(也是你评论中提到的那一行)给我一个空白页,就好像有错误一样。很可能有错误。将
放在页面的最上方。这将告诉你/我错误是什么。仍然给我一个空白页。如果我删除该行并保留它,它将按应有方式加载页面。谢谢。这与上面列出的代码在同一页上吗?很少不知道该放在哪里。是的,sql查询添加了行并替换了您的行。HTML按钮会放在构造()中的某个地方,不管您如何布置它。它可能更像是
思想谢谢,我似乎无法让它工作。您更新的最后一行(也是您评论中提到的那一行)给我一个空白页,好像有错误。很可能有错误。将
放在页面的最上方。这将告诉你/我错误是什么。仍然给我一个空白页。如果我删除该行并保持它按应有的方式加载页面。