结果隔离时显示其他表单数据 [英] Show Additional Form Data when Result is Isolated

查看:169
本文介绍了结果隔离时显示其他表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,将调查结果显示到网页中。目前,当用户点击在这里查看时,它需要他们到该ID的单个条目。当它被点击我想它也显示额外的结果(也是同一数据库的结果的一部分)。

I have a form that displays the results from a survey into a webpage. At the moment, when a user clicks on the 'View Here' it takes them to the individual entry for that ID. When it is clicked I would like it to also show additional results (also part of the results from the same database).

任何想法我如何做到这一点?为了澄清,它不应该显示,直到ID被点击以单出该条目 - 否则它显示它们全部一个接一个。

Any idea how I do this? Just to clarify, it should not show until the ID is clicked to single out that entry - otherwise it shows them all in full one after the other.

<?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>';
}

?>

点击View Here后,我想显示的其他代码显示):

Additional code that I would like to show once 'View Here' is clicked (so when the individual entry is shown):

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>

";


推荐答案

如果这个工作,我没有测试它,所以请确保你保存的任何你迄今为止的副本。它需要填写数据库凭据:

See if this works. I have not tested it, so make sure you save a copy of whatever you have so far. It requires database credentials to be filled out:

课程:

<?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);
?>

这篇关于结果隔离时显示其他表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆