将 MySQLi 准备好的语句结果回显到另一页
Echo MySQLi Prepared Statement Results to Another Page
我一直在尝试使用 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>
更新:我已经进行了建议的更改,但已发送到我的 'else' 错误页面。我知道当我在与查询相同的页面上显示结果时,我 运行 带回并显示了结果。
这是处理页面的新代码
<?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>
我没有收到任何 'errors' 报告,所以我觉得我快要解决这个问题了。
更新 #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>
更新 #3 - 当我使用 var_dump($results) 时,结果显示在处理页面上而不是显示页面上。
处理页面(版本 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();
?>
问题是您没有在进程页面中创建数组。您的 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>";
不应出现在显示脚本的循环中。循环只处理每一行。
通过删除 'Display Page' 顶部的所有 'includes',我能够使结果在 'Display Page' 上正确显示,并且只有 'session_start()' 和然后是它下面的 '$results = $_SESSION['results']'。当只有这两个语句时它起作用了。
我一直在尝试使用 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>
更新:我已经进行了建议的更改,但已发送到我的 'else' 错误页面。我知道当我在与查询相同的页面上显示结果时,我 运行 带回并显示了结果。
这是处理页面的新代码
<?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>
我没有收到任何 'errors' 报告,所以我觉得我快要解决这个问题了。
更新 #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>
更新 #3 - 当我使用 var_dump($results) 时,结果显示在处理页面上而不是显示页面上。
处理页面(版本 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();
?>
问题是您没有在进程页面中创建数组。您的 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>";
不应出现在显示脚本的循环中。循环只处理每一行。
通过删除 'Display Page' 顶部的所有 'includes',我能够使结果在 'Display Page' 上正确显示,并且只有 'session_start()' 和然后是它下面的 '$results = $_SESSION['results']'。当只有这两个语句时它起作用了。