テーブルのフィルタを作成しましたが、最初はうまくいきましたが、日付の入力フォームをdatepickerに置き換えるとすぐに、日付の作品と他のものは無視され、私はそれがこのように動作する理由は何も見ることができません。datepickerからの入力でドロップダウンリストの入力が途切れます
これは、フィルタオプションのドロップダウンリストを作成する部分である:
echo "<form action='listTimes.php' method='post'>
<table>
<caption><b>Filter By:</b></caption>
<tr>
<th>Task Name</th>
<th>Task Stage</th>
<th>Name</th>
<th>Date</th>
</tr>
<tr>
<td>";
// first filter option - dropdown
$sql = "SELECT DISTINCT taskName FROM tasks";
$result = mysqli_query($link, $sql);
echo "<select name='taskName'>";
echo "<option selected='selected' value='' disabled='disabled'></option>";
while ($row = mysqli_fetch_array($result)) {
if (isset($row['taskName'])) {
echo "<option value='" . $row['taskName'] . "'>" . $row['taskName'] . "</option>";
}
}
echo "</select>
</td>
<td>";
// second filter option - dropdown
$sql = "SELECT DISTINCT taskStage FROM taskattributes";
$result = mysqli_query($link, $sql);
echo "<select name='taskStage'>
<option selected='selected' value='' disabled='disabled'></option>";
while ($row = mysqli_fetch_array($result)) {
if (isset($row['taskStage'])) {
echo "<option value='" . $row['taskStage'] . "'>" . $row['taskStage'] . "</option>";
}
}
echo "</select>
</td>
<td>";
// third filter option - dropdown
$sql = "SELECT DISTINCT userName FROM users";
$result = mysqli_query($link, $sql);
echo "<select name='userName'>";
echo "<option selected='selected' value='' disabled='disabled'></option>";
while ($row = mysqli_fetch_array($result)) {
if (isset($row['userName'])) {
echo "<option value='" . $row['userName'] . "'>" . $row['userName'] . "</option>";
}
}
/* fourth filter option, was just a simple text input at first. Now I changed it to a datepicker, which works, but the other three filter options stopped working at this point */
echo "</select>
</td>
<td>
<input type='text' class='datepicker' name='entryDate'>
</td>
</tr>
</table>
<div align='center'> <input type='submit' value='Filter'></div>
</form>
の背後にあるフィルタ機構は非常に貧弱ですが、うまく動作します:
if(!isset($_POST['taskName']) && !isset($_POST['taskStage']) && !isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$sql = "SELECT * FROM timeEntry";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && !isset($_POST['taskStage']) && !isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && isset($_POST['taskStage']) && !isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND taskStage='$taskStage'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && isset($_POST['taskStage']) && !isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND taskStage='$taskStage' AND userName='$userName'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && isset($_POST['taskStage']) && isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND taskStage='$taskStage' AND userName='$userName' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && isset($_POST['taskStage']) && isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskStage='$taskStage' AND userName='$userName' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && !isset($_POST['taskStage']) && isset($_POST['userName']) && isset($_POST['entryDate']))
{
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE userName='$userName' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && !isset($_POST['taskStage']) && !isset($_POST['userName']) && isset($_POST['entryDate']))
{
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && isset($_POST['taskStage']) && !isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskStage='$taskStage'AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && !isset($_POST['taskStage']) && isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND userName='$userName'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && !isset($_POST['taskStage']) && isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND userName='$userName' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && isset($_POST['taskStage']) && !isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$sql = "SELECT * FROM timeEntry WHERE taskStage='$taskStage'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && isset($_POST['taskStage']) && !isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND taskStage='$taskStage' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && !isset($_POST['taskStage']) && isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$sql = "SELECT * FROM timeEntry WHERE userName='$userName'";
$result = $link->query($sql);
}
elseif (isset($_POST['taskName']) && !isset($_POST['taskStage']) && !isset($_POST['userName']) && isset($_POST['entryDate']))
{
$taskName = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskName']));
$entryDate = mysqli_real_escape_string($link, htmlspecialchars($_POST['entryDate']));
$sql = "SELECT * FROM timeEntry WHERE taskName='$taskName' AND entryDate='$entryDate'";
$result = $link->query($sql);
}
elseif (!isset($_POST['taskName']) && isset($_POST['taskStage']) && isset($_POST['userName']) && !isset($_POST['entryDate']))
{
$taskStage = mysqli_real_escape_string($link, htmlspecialchars($_POST['taskStage']));
$userName = mysqli_real_escape_string($link, htmlspecialchars($_POST['userName']));
$sql = "SELECT * FROM timeEntry WHERE taskStage='$taskStage' AND userName='$userName'";
$result = $link->query($sql);
}
echo "<table class='top1' border='1'>
<tr>
<th>Entry No.</th>
<th>Task/Activity</th>
<th>Task Stage</th>
<th>User Name</th>
<th>Time Spent</th>
<th>Date</th>
<th>Edit Entry</th>
<th>Delete Entry</th>
</tr>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>
<td align='center'>" . $row['timeId'] . "
</td>";
echo "<td>" . $row['taskName'] . "</td>";
echo "<td>" . $row['taskStage'] . "</td>";
echo "<td>" . $row['userName'] . "</td>";
echo "<td align='center'>" . $row['timeSpent'] . "</td>";
$originaldate = mysqli_real_escape_string($link, $row['entryDate']);
$newdate = date("d/m/Y", strtotime($row['entryDate']));
echo "<td align='center'>" . $newdate . "</td>";
echo "<td align='center'><a href='editAllTimes.php?timeId=" . $row["timeId"] . "'>Edit</a></td>";
echo "<td align='center'><a href='deleteAllTime.php?timeId=" . $row["timeId"] . "' onclick='return checkDelete()'>Delete</a></td>
</tr>";
}
echo "</table>";
}
コードのこの作品見た目が悪く、日付ピッカーを追加する前にうまくいきました。
<input type='text' class='datepicker' name='entryDate'>
私は名=「ENTRYDATE」他のフィルタが動作し、DatePickerのも、私は、フィルタとその結果の日付フィルタのdoesnを押すと日付が記録されていない名前の属性を削除した場合
- :奇妙な行動に気づきました仕事はありません。
- 名前属性がの場合、名前= 'entryDate'の場合、他の3つのフィルタは機能しなくなり、日付フィルタのみが機能します。
この現象が発生する理由はありますか?と任意のソリューション?
2番目の考えでは、最初に日付フィルタは ''のドロップダウンリストで、 ''という形式ではありませんでした。 これを ''に置き換えるのは、issetを使ってフォームの値をテストしていたためです。 –