当结果被隔离时显示其他表单数据


Show Additional Form Data when Result is Isolated

我有一个表单,从一个调查结果显示到一个网页。目前,当用户单击"View Here"时,它会将他们带到该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>
";

看看这是否有效。我还没有测试过它,所以请确保保存到目前为止的所有内容的副本。它要求填写数据库凭据:

类:

<?php
    interface   Database
        {   
            public  static  function SetConnection($host,$username,$password,$database);
        }
    interface   Questionnaire
        {
            public  function Display();
            public  function DisplaySingle();
        }
    class   MySQLConn implements Database
        {           
            protected   static  $host;
            protected   static  $username;
            protected   static  $password;
            protected   static  $database;
            public      static $connect;
            private function __construct()
                {
                }
            public  static  function SetConnection($host = "***",$username = "***",$password = "***",$database = "***")
                {
                    self::$host     =   $host;
                    self::$username =   $username;
                    self::$password =   $password;
                    self::$database =   $database;
                    self::$connect  =   (!isset(self::$connect))? self::Initialize() : self::$connect;
                }
            private static  function Initialize($use = 'PDO')
                {
                    if($use == 'PDO') {
                            try {
                                    $con    =   new PDO('mysql:host='.self::$host.';dbname='.self::$database, self::$username, self::$password);
                                    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                                    return $con;
                                }
                            catch (PDOException $e) {
                                    die($e->getMessage());
                                }
                        }
                    else
                        return new mysqli(self::$host, self::$username, self::$password, self::$database);
                }
        }
    class   guestquestionnaireEntry implements Questionnaire
        {
            public  $id,
                    $date_submitted,
                    $choice,
                    $expectations,
                    $res,
                    $res_information,
                    $res_staff,
                    $further_comments1,
                    $entry;
            public function __construct()
                {
                    if(empty($_GET['focus']))
                        $this->entry = $this->DisplaySingle();
                    else
                        $this->entry = $this->Display();
                }
            public  function DisplaySingle()
                {
                    ob_start(); ?>
                <table border='1' align='center'>
                    <tr class='tablelist' style='font-size: 8pt;' >
                        <td width='5%' colspan='2'><?php echo $this->ID; ?></td>
                        <td width='40%' colspan='2'><b>Date Received: </b><?php echo $this->date_submitted; ?></td>
                        <td width='45%' colspan='2'><?php echo $this->name; ?></td>
                        <td width='10%'><a href="?ID=<?php echo strip_tags($this->ID); ?>&focus=true">View here</a></td>
                    </tr>
                </table>
                <?php
                    $data   =   ob_get_contents();
                    ob_end_clean();
                    return $data;
                }
            public  function Display()
                {
                    ob_start(); ?>
                    <tr style='font-size: 8pt;'>
                        <td width='60%'><a href="?ID=<?php echo $this->ID; ?>">ID</a></td>
                        <td width='40%' colspan='2'><?php echo $this->date_submitted; ?></td>
                    </tr>
                    <tr style='text-align: left; font:arial;'>
                        <td><h3>Date Submitted: <?php echo $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'><?php echo $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'><?php echo $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%'><?php echo $this->res; ?></td>
                        </tr>
                        <BR>
                        <tr style='font-size: 8pt;'>
                            <td>Hotel information offered: </td>
                            <td width='40%'><?php echo $img2; ?></td>
                            <td width='5%'><?php echo $this->res_information; ?></td>
                        </tr>
                        <BR>
                        <tr style='font-size: 8pt;'>
                            <td>Warmth and friendliness of staff: </td>
                            <td width='40%'><?php echo $img3; ?></td>
                            <td width='5%'><?php echo $this->res_staff; ?></td>
                        </tr>
                        <BR>
                        <tr style='font-size: 8pt;'>
                            <td colspan='3'>Further Comments: </BR>
                                </BR>
                                <?php echo $this->further_comments1; ?></td>
                        </tr>
                        <BR>
                    </table>
                    <BR>
                    <p>Back to List</p>
                    <?php
                    $data   =   ob_get_contents();
                    ob_end_clean();
                    return $data;
                }
        }
?>
使用

>

<?php
    //**********************************************************************************
    // Add the classes here by way of include() or just pasted at the top of the page...
    //**********************************************************************************
    // Start up the database connection
    MySQLConn::SetConnection();
    // Assign database connection
    $handler    =   MySQLConn::$connect;
    // 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');
    // Assign data
    while($r = $query->fetch()) {
            $setEntry[] =   $r->entry;
        }
    // Implode with break
    if(isset($setEntry))
        echo implode("<br />",$setEntry);
?>