私がデザインしているこのウェブサイトに問題があり、目をつぶる前に助けを求めています。次のスクリプトの期待される結果は、次のような入力フォームを持つWebページです(
James Craig | Week 7 | <INPUT>max</INPUT | <INPUT>ctrl</INPUT>
Jo Mama | Week 7 | <INPUT>max</INPUT | <INPUT>ctrl</INPUT>
しかし、私が実際に目にするのは次のとおりです。
James Craig Week 7 max: ctrl:
テキスト入力フィールドやテーブルの書式設定はありません。また、二人称は表示されません。
次に:ページがロックされ、ブラウザがクラッシュします。
ループが終了していないのではないかと思いますが、この時点で迷子になっています。質問することがたくさんあることは知っていますが、誰かが私をここでまっすぐにすることができますか?:)
私が扱っている基本データ:
データベースサンプルデータ
Table Name: loginUsers
--------------------------------------------------------
| storeID | login | password |
|-------------------|----------------|-----------------|
| 0460 | store0460 | store0460 |
--------------------------------------------------------
Table Name: specialistData
--------------------------------------------------------
| specialistID | week | max | ctrl |
|------------------------------------------------------|
| 1 | 1 | 28.50 | 19.99 |
| 1 | 2 | 17.85 | 21.99 |
| 1 | 3 | 16.99 | 99.99 |
| 1 | 4 | 28.50 | 19.99 |
| 1 | 5 | 28.50 | 19.99 |
| 1 | 6 | 28.50 | 19.99 |
| 2 | 1 | 28.50 | 19.99 |
| 2 | 2 | 17.85 | 21.99 |
| 2 | 3 | 16.99 | 99.99 |
| 2 | 4 | 28.50 | 19.99 |
| 2 | 5 | 28.50 | 19.99 |
| 2 | 6 | 28.50 | 19.99 |
--------------------------------------------------------
Table Name: usersSpecialists
--------------------------------------------------------
| storeID | specialistID | name |
|-------------------|----------------|-----------------|
| 0460 | 1 | James Craig |
| 0460 | 2 | Jo Mama |
--------------------------------------------------------
問題のPHPドキュメント(DB接続文字列を削除しましたが、正常に機能することを保証します)
<?php
//Initialize the session
session_start();
//Check for existing session. Route to login if not
if(!isset( $_SESSION['username'])){
header('Location: ../index.php');
}
?>
<?php include(dirname(__FILE__)."/functions.php"); ?>
<html>
<head>
<title>Weekly Data</title>
<link href="portal.css" rel="stylesheet">
</head>
<body>
<div id="masthead">
<ul class="nav nav-pills pull-right">
<li class = "active"><a href="#">View Report</a></li>
<li class = "active"><a href="#">Edit Specialists</a></li>
<li class = "active"><a href="logout.php">Logout</a></li>
</ul>
<h3 class="muted">Sales Specialist Ranker - Weekly Data</h3>
</div>
<hr>
<div id="jumbotron"><center>
<h1>Enter Weekly Data</h1>
<form action="submitData.php method="GET">
</form>
<a class="btn btn-large btn-success" href="#">Submit</a>
</center></div>
<?php
//This will determine the current week, compare it to the last entry for each specialist, and create a form to request any needed data.
//Obtain currently logged in store (Store Number)
$currentStore = $_SESSION['username'];
//Obtain Current Week
$currentWeek = date("W");
//Obtain list of specialists (specialist ID)
//Create temp mysqli object
$specialistList = new mysqli();
//Grab specialist list
$specialistList = getSpecialists($currentStore);
//Loop through each specialist and generate form
//Start Form
echo "<form name='specialistData' action='submitData.php' method='get'>";
//Start Loop
while($row = $specialistList->fetch_array(MYSQLI_ASSOC)){
//Start HTML Table
echo "<table class='dataEntry'>";
//create temp mysqli object
$lastWeek = new mysqli();
//Get last entry for specialist
$lastWeekData = lastEntry($row['specialistID']);
$lastWeekData = $lastWeekData->fetch_array(MYSQLI_ASSOC);
$lastWeek = $lastWeekData['week'];
$specialistID = $row['specialistID'];
$specialistName = $lastWeekData['name'];
//compare last week to current week
//Begin loop
while($lastWeek < $currentWeek){
//create HTML Input for each specialist
echo "<tr>\n
<td>$specialistName</td>\n
<td>Week: $lastWeek</td>\n
<td>Max: <input type='text' name='".$specialistID."-".$lastWeek."-max /></td>\n
<td>Max: <input type='text' name='".$specialistID."-".$lastWeek."-ctrl /></td>\n
</tr>\n";
$lastweek++;
}
//Close HTML table for this specialist
echo "</table>";
}
//Close HTML Form
echo "</form>";
?>
<hr>
<div class="footer">
<p> Footer Here</p>
</div>
</body>
</html>
これが私のfunctions.phpです
<?php //FUNCTIONS
function getSpecialists($user){
/*
PURPOSE: GET LIST OF SPECIALISTS THAT BELONG TO CURRENT USER
ARGUMENTS: $user{USER ID - STRING}
RETURN: MYSQLI OBJECT CONTAINING RESULT LIST {specialistID}
*/
//Include DB Strings
$DB_HOST = "****";
$DB_NAME = "****";
$DB_USER = "****";
$DB_PASS = "****";
//Query create the SQL object
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
//Plan for error
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n". mysqli_connect_error(error)." \n WHEN: OBTAINING SPECIALIST LIST");
exit();
}
//Create QUERY to return {specialistID}
$sql = "SELECT usersSpecialists.specialistID
FROM usersSpecialists
INNER JOIN loginUsers
ON usersSpecialists.storeID = loginUsers.storeID
WHERE loginUsers.login = '$user'";
//Launch the query
$specialistResults = $mysqli->query($sql);
//Send back results of query
return $specialistResults;
}
function lastEntry($specialist){
/*
PURPOSE: GET THE LATEST ENTRY (WEEK NUMBER) FOR GIVEN SPECIALIST
ARGUMENTS: $specialistID{SPECIALIST IN QUESTION - INT}
RETURN: MYSQLI OBJECT CONTAINING RESULT LIST {week, name}
*/
//Include DB connection strings
$DB_HOST = "****";
$DB_NAME = "****";
$DB_USER = "****";
$DB_PASS = "****!";
//Query create the SQL object
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
//Plan for error
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n". mysqli_connect_error(error)." \n WHEN: OBTAINING SPECIALIST LIST");
exit();
}
//Create SQL query
$sql = "SELECT specialistData.week, usersSpecialists.name
FROM specialistData
INNER JOIN usersSpecialists
ON specialistData.specialistID = usersSpecialists.specialistID
WHERE specialistData.specialistID = $specialist
ORDER BY specialistData.week DESC
LIMIT 1";
//Launch SQL query
$lastWeek = $mysqli->query($sql);
//Return mysqli result $lastWeek {week, name}
return $lastWeek;
}
?>