Echo MySQLi准备声明结果到另一页

时间:2015-06-30 18:44:33

标签: php mysqli prepared-statement echo

我一直在尝试使用MySQLi-> prepare语句来查询数据库,然后将结果回显到我网站的另一个页面。我已经能够将其工作并将结果显示在与查询相同的页面上,但无法将结果放到其他网页上。请帮忙..这是我的代码。

以下是流程页面的代码:

    <?php
    include_once 'db_connect.php';
    include_once 'psl-config.php';
    include_once 'functions.php';
    sec_session_start();

    $error_msg = "";

    if (isset($_GET['subject']))
    $subject = $_GET['subject'];
    if (isset($_GET['set_date']))
    $set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
while($results = $query->fetch()) {
    $subject = $results['subject'];
    $set_date = $results['set_date'];
    $set_time = $results['set_time'];
    $result = $results['result'];
    $employee = $results['employee'];
    $project = $results['project'];
    $source = $results['source'];
    $appt_date = $results['appt_date'];
    $branch = $results['branch'];
    $fname = $results['fname'];
    $lname = $results['lname'];
    $last_four = $results['last_four'];
    $phone = $results['phone'];
    $city = $results['city'];
    $state = $results['state'];
    $zip = $results['zip'];
    $monthly_net = $results['monthly_net'];
    $job_time = $results['job_time'];
}
$_SESSION['subject'] = $subject;
$_SESSION['set_date'] = $set_date;
$_SESSION['set_time'] = $set_time;
$_SESSION['result'] = $result;
$_SESSION['employee'] = $employee;
$_SESSION['project'] = $project;
$_SESSION['source'] = $source;
$_SESSION['appt_date'] = $appt_date;
$_SESSION['branch'] = $branch;
$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['last_four'] = $last_four;
$_SESSION['phone'] = $phone;
$_SESSION['city'] = $city;
$_SESSION['state'] = $state;
$_SESSION['zip'] = $zip;
$_SESSION['monthly_net'] = $monthly_net;
$_SESSION['job_time'] = $job_time;
if ($_SESSION['employee']) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>

以下是我想要显示结果的页面的代码:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            if(isset($_SESSION['subject']) && isset($_SESSION['set_date']) && isset($_SESSION['set_time']) && isset($_SESSION['result']) && isset($_SESSION['employee']) && isset($_SESSION['project']) && isset($_SESSION['source']) && isset($_SESSION['appt_date']) && isset($_SESSION['branch']) && isset($_SESSION['fname']) && isset($_SESSION['lname']) && isset($_SESSION['last_four']) && isset($_SESSION['phone']) && isset($_SESSION['city']) && isset($_SESSION['state']) && isset($_SESSION['zip']) && isset($_SESSION['monthly_net']) && isset($_SESSION['job_time'])) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";

            for($i=0;$i<count($_SESSION['subject']);$i++) {

        echo "<tr>";
        echo "<td>{$_SESSION['subject'][$i]}</td>";
        echo "<td>{$_SESSION['set_date'][$i]}</td>";
        echo "<td>{$_SESSION['set_time'][$i]}</td>";
        echo "<td>{$_SESSION['result'][$i]}</td>";
        echo "<td>{$_SESSION['employee'][$i]}</td>";
        echo "<td>{$_SESSION['project'][$i]}</td>";
        echo "<td>{$_SESSION['source'][$i]}</td>";
        echo "<td>{$_SESSION['appt_date'][$i]}</td>";
        echo "<td>{$_SESSION['branch'][$i]}</td>";
        echo "<td>{$_SESSION['fname'][$i]}</td>";
        echo "<td>{$_SESSION['lname'][$i]}</td>";
        echo "<td>{$_SESSION['last_four'][$i]}</td>";
        echo "<td>{$_SESSION['phone'][$i]}</td>";
        echo "<td>{$_SESSION['city'][$i]}</td>";
        echo "<td>{$_SESSION['state'][$i]}</td>";
        echo "<td>{$_SESSION['zip'][$i]}</td>";
        echo "<td>{$_SESSION['monthly_net'][$i]}</td>";
        echo "<td>{$_SESSION['job_time'][$i]}</td>";
        echo "</tr>";
        echo "</table>";
            }

}else{

    echo "No Records Found";
}

 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

更新:我已经做出了已经建议的更改,但是我已经发送到我的“其他”#39;错误页面。我知道我正在运行的查询带回来并在我在与查询相同的页面上显示结果时显示结果。

以下是Processing Page

的新代码
<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results = $row;
}
$_SESSION['results'] = $results;
if ($results) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>

显示页面的新代码:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            $results = $_SESSION['results'];
         if($results) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";


            foreach($_SESSION['results'] as $result) {

                echo "<tr>";
                echo "<td>{$result['subject']}</td>";
                echo "<td>{$result['set_date']}</td>";
                echo "<td>{$result['set_time']}</td>";
                echo "<td>{$result['result']}</td>";
                echo "<td>{$result['employee']}</td>";
                echo "<td>{$result['project']}</td>";
                echo "<td>{$result['source']}</td>";
                echo "<td>{$result['appt_date']}</td>";
                echo "<td>{$result['branch']}</td>";
                echo "<td>{$result['fname']}</td>";
                echo "<td>{$result['lname']}</td>";
                echo "<td>{$result['last_four']}</td>";
                echo "<td>{$result['phone']}</td>";
                echo "<td>{$result['city']}</td>";
                echo "<td>{$result['state']}</td>";
                echo "<td>{$result['zip']}</td>";
                echo "<td>{$result['monthly_net']}</td>";
                echo "<td>{$result['job_time']}</td>";
                echo "</tr>";

            }


}else{

    echo "No Records Found";
}


 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

我没有得到任何错误&#39;报告所以我觉得我接近解决这个问题。

更新#2 - 仍然被发送到错误页面。以下是代码现在的样子:

流程页面:

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results[] = array(
    'subject' => $subject,
    'set_date' => $set_date,
    'set_time' => $set_time,
    'result' => $result,
    'employee' => $employee,
    'project' => $project,
    'source' => $source,
    'appt_date' => $appt_date,
    'branch' => $branch,
    'fname' => $fname,
    'lname' => $lname,
    'last_four' => $last_four,
    'phone' => $phone,
    'city' => $city,
    'state' => $state,
    'zip' => $zip,
    'monthly_net' => $monthly_net,
    'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;
if ($results) {
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?> 

显示页面:

<?php
include_once 'includes/db_connect.php';
include_once 'includes/functions.php';
include_once 'includes/appointments.inc.php';
sec_session_start();
?>

<!doctype html>
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>Welcome | Mountain and Alpine Loan Centers</title>
        <meta name="description" content="Mountain and Alpine Loan Centers">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
        <script type="text/JavaScript" src="js/sha512.js"></script> 
        <script type="text/JavaScript" src="js/forms.js"></script> 
    </head>
    <body>
        <!--[if lt IE 8]>
            <p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        <div align="center">
        <img src="../img/Logo4_Black_Red.jpg" height="126" width="266">
        <nav id="nav01"></nav></div>
        <div align="center"><br><br><br> 


            <?php 
            $results = $_SESSION['results'];
         if($results) {
    echo "<table border='1'>";
    echo "<tr>";
    echo "<th>Subject</th>";
    echo "<th>Date Set</th>";
    echo "<th>Time Set</th>";
    echo "<th>Result</th>";
    echo "<th>Employee</th>";
    echo "<th>Project</th>";
    echo "<th>Source</th>";
    echo "<th>Appointment Date</th>";
    echo "<th>Branch</th>";
    echo "<th>First Name</th>";
    echo "<th>Last Name</th>";
    echo "<th>Last Four</th>";
    echo "<th>Phone</th>";
    echo "<th>City</th>";
    echo "<th>State</th>";
    echo "<th>Zip</th>";
    echo "<th>Monthly Net</th>";
    echo "<th>Time at Job</th>";
    echo "</tr>";


            foreach($_SESSION['results'] as $result) {

                echo "<tr>";
                echo "<td>{$result['subject']}</td>";
                echo "<td>{$result['set_date']}</td>";
                echo "<td>{$result['set_time']}</td>";
                echo "<td>{$result['result']}</td>";
                echo "<td>{$result['employee']}</td>";
                echo "<td>{$result['project']}</td>";
                echo "<td>{$result['source']}</td>";
                echo "<td>{$result['appt_date']}</td>";
                echo "<td>{$result['branch']}</td>";
                echo "<td>{$result['fname']}</td>";
                echo "<td>{$result['lname']}</td>";
                echo "<td>{$result['last_four']}</td>";
                echo "<td>{$result['phone']}</td>";
                echo "<td>{$result['city']}</td>";
                echo "<td>{$result['state']}</td>";
                echo "<td>{$result['zip']}</td>";
                echo "<td>{$result['monthly_net']}</td>";
                echo "<td>{$result['job_time']}</td>";
                echo "</tr>";

            }


}else{

    echo "No Records Found";
}


 ?>

            <p>Return to the<a href="index.php">login page</a></p>
        </div>


        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.11.3.min.js"><\/script>')</script>
        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="../js/script.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='https://www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>
    </body>
</html>

UPDATE#3 - 当我使用var_dump($ results)时,结果会显示在Process Page而不是Display Page上。

流程页面(版本3):

<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
include_once 'functions.php';
sec_session_start();

$error_msg = "";

if (isset($_GET['subject']))
$subject = $_GET['subject'];
if (isset($_GET['set_date']))
$set_date = $_GET['set_date'];
if (isset($_GET['set_time']))
$set_time = $_GET['set_time'];
if (isset($_GET['result']))
$result = $_GET['result'];
if (isset($_GET['employee']))
$employee = $_GET['employee'];
if (isset($_GET['project']))
$employee = $_GET['project'];
if (isset($_GET['source']))
$source = $_GET['source'];
if (isset($_GET['appt_date']))
$appt_date = $_GET['appt_date'];
if (isset($_GET['branch']))
$branch = $_GET['branch'];
if (isset($_GET['fname']))
$fname = $_GET['fname'];
if (isset($_GET['lname']))
$lname = $_GET['lname'];
if (isset($_GET['last_four']))
$last_four = $_GET['last_four'];
if (isset($_GET['phone']))
$phone = $_GET['phone'];
if (isset($_GET['city']))
$city = $_GET['city'];
if (isset($_GET['state']))
$state = $_GET['state'];
if (isset($_GET['zip']))
$zip = $_GET['zip'];
if (isset($_GET['monthly_net']))
$monthly_net = $_GET['monthly_net'];
if (isset($_GET['job_time']))
$job_time = $_GET['job_time'];

$query = $mysqli->prepare("SELECT subject, set_date, set_time, result, employee, project, source, appt_date, branch, fname, lname, last_four, phone, city, state, zip, monthly_net, job_time FROM appointments WHERE set_date LIKE CONCAT('%', ?, '%') AND result LIKE CONCAT('%', ?, '%') AND employee LIKE CONCAT('%', ?, '%') AND project LIKE CONCAT('%', ?, '%') AND source LIKE CONCAT('%', ?, '%') AND appt_date LIKE CONCAT('%', ?, '%') AND branch LIKE CONCAT('%', ?, '%') AND fname LIKE CONCAT('%', ?, '%') AND lname LIKE CONCAT('%', ?, '%') AND last_four LIKE CONCAT('%', ?, '%') AND phone LIKE CONCAT('%', ?, '%') AND city LIKE CONCAT('%', ?, '%') AND state LIKE CONCAT('%', ?, '%') AND zip LIKE CONCAT('%', ?, '%') ORDER BY employee");
$query->bind_param('ssssssssssssss', $_GET['set_date'], $_GET['result'], $_GET['employee'], $_GET['project'], $_GET['source'], $_GET['appt_date'], $_GET['branch'], $_GET['fname'], $_GET['lname'], $_GET['last_four'], $_GET['phone'], $_GET['city'], $_GET['state'], $_GET['zip']);
$query->execute();
$query->store_result();
$query->bind_result($subject, $set_date, $set_time, $result, $employee, $project, $source, $appt_date, $branch, $fname, $lname, $last_four, $phone, $city, $state, $zip, $monthly_net, $job_time);
$results = array();
while($row = $query->fetch()) {
    $results[] = array(
    'subject' => $subject,
    'set_date' => $set_date,
    'set_time' => $set_time,
    'result' => $result,
    'employee' => $employee,
    'project' => $project,
    'source' => $source,
    'appt_date' => $appt_date,
    'branch' => $branch,
    'fname' => $fname,
    'lname' => $lname,
    'last_four' => $last_four,
    'phone' => $phone,
    'city' => $city,
    'state' => $state,
    'zip' => $zip,
    'monthly_net' => $monthly_net,
    'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;
if($results) {
        var_dump($results); 
        header('Location: ../appointments_page.php');
    } else {
        header('Location: ../appointments.php?error=1');
    }

$query->free_result();
$mysqli->close();
?>

2 个答案:

答案 0 :(得分:1)

问题是您没有在流程页面中创建数组。您的while循环每次都会覆盖$subject之类的变量,它不会将当前值附加到数组中。它应该是:

$_SESSION['subject'] = array();
$_SESSION['set_date'] = array();
...
while($results = $query->fetch()) {
    $_SESSION['subject'][] = $subject;
    $_SESSION['set_date'][] = $set_date;
    ...
}

但是,我不会为每列使用单独的变量,我只是将所有内容都收集到一个多维数组中:

$results = array();
while ($row = $query->fetch()) {
    $results[] = array(
        'subject' => $subject,
        'set_date' => $set_date,
        'set_time' => $set_time,
        'result' => $result,
        'employee' => $employee,
        'project' => $project,
        'source' => $source,
        'appt_date' => $appt_date,
        'branch' => $branch,
        'fname' => $fname,
        'lname' => $lname,
        'last_four' => $last_four,
        'phone' => $phone,
        'city' => $city,
        'state' => $state,
        'zip' => $zip,
        'monthly_net' => $monthly_net,
        'job_time' => $job_time
    );
}
$_SESSION['results'] = $results;

然后在显示页面中,它将是:

foreach ($_SESSION['results'] as $result) {
    echo "<tr>";
    echo "<td>{$result['subject']}</td>";
    echo "<td>{$result['set_date']}</td>";
    echo "<td>{$result['set_time']}</td>";
    echo "<td>{$result['result']}</td>";
    echo "<td>{$result['employee']}</td>";
    echo "<td>{$result['project']}</td>";
    echo "<td>{$result['source']}</td>";
    echo "<td>{$result['appt_date']}</td>";
    echo "<td>{$result['branch']}</td>";
    echo "<td>{$result['fname']}</td>";
    echo "<td>{$result['lname']}</td>";
    echo "<td>{$result['last_four']}</td>";
    echo "<td>{$result['phone']}</td>";
    echo "<td>{$result['city']}</td>";
    echo "<td>{$result['state']}</td>";
    echo "<td>{$result['zip']}</td>";
    echo "<td>{$result['monthly_net']}</td>";
    echo "<td>{$result['job_time']}</td>";
    echo "</tr>";
}

此外,echo "</table>";不应位于显示脚本的循环中。循环只处理每一行。

答案 1 :(得分:0)

我能够在&#39;显示页面上正确显示结果。通过删除所有&#39;包括&#39;位于显示页面顶部的&#39;并且只有&#39; session_start()&#39;然后&#39; $ results = $ _SESSION [&#39;结果&#39;]&#39;在它下面。只有这两个陈述才有效。