duan7664 2019-06-24 06:43
浏览 28

如果表单提交为空,则Datepicker不适用于下一页

I am using jQuery datepicker to filter the search results from database. There is a search form in index page (same form is also in search.php) and it directs the user to search.php page after inserting the inputs and displaying the data table in search.php page. Datepicker works fine under normal conditions but when I sumbit the form empty in index.php datepicker is not triggered in search.php.

This is the form in index.php


<section id="searchForm">
 <div class="container">
   <h1>Search</h1>
    <h3>See Proc</h3>
      <form id="form" align="center" action="search.php" method="GET">
    <input class="search_input" type="text" name="from" placeholder="From...">
    <input class="search_input" type="text" name="where" placeholder="Where...">
    <input class="search_input" type="text" id="datepicker" name="date" placeholder="Date...">
    <select id="select" name="type">
    <option value="package">Package</option>
    <option value="paper">Paper</option>
    </select>
    <input class="btn btn-secondary" name="search_btn" type="submit" value="Search">
    </form>
</div>
</section>

<script>
$(document).ready(function() {
  $('#datepicker').datepicker({
  });
});
</script>

This is the section from search.php

<section id="searchTools">
<div class="container">
<form id="form" align="center" action="search.php" method="GET">
<input class="search_input" type="text" name="from" placeholder="From...">
<input class="search_input" type="text" name="where" placeholder="Where...">
<input class="search_input" type="text" id="datepicker" name="date" placeholder="Date...">
<select class="search_input" name="type">
<option value="package">Package</option>
<option value="paper">Paper</option>
</select>
<input class="submit_button" name="search_btn" type="submit" value="Search">
</form>
</div>
</section>


<section id="results">
 <div class="container">
  <table clas="table table-hover">
    <tr>
    <th>Name Surname</th>
    <th>Where</th>
    <th>From</th>
    <th>Date</th>
    <th>Price</th>
    <th>Type</th>
    </tr>

<?php
include_once "db_connect.php";

$from = $_GET['from'];
$where = $_GET['where'];
$date = $_GET['date'];
$type = $_GET['type'];
$proc_id = $_GET['proc_id'];

$procDate = DateTime::createFromFormat('m/d/Y', $date);
$procDate = $procDate->format('Y-m-d');
//define how many results you want per page
$results_per_page = 8;
//number of results stored in database
"SELECT * FROM proc WHERE p_from = '".$from."' and p_where = '".$where."' and type= '".$type."' ";
$query = mysqli_query($conn, $sql);
$num_rows = mysqli_num_rows($query);
//determine number of total pages available
$num_of_pages = ceil($num_rows/$results_per_page);

//determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
header("search.php?page=1");
}else{
$page = $_GET['page'];
}
//determine the SQL LIMIT starting number for the result on the displaying page
$page_first_result = ($page - 1)*$results_per_page;

//retrive selected results from database and display them on page
$sql = "SELECT * FROM proc WHERE p_from = '".$from."' and p_where = '".$where."' and type= '".$type."' and p_date >= '".$procDate."' ORDER BY p_date, price LIMIT " . $page_first_result . " , " . $results_per_page . "";

$query = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_array($query, MYSQLI_ASSOC)) {

echo '<tr onclick="content(\''. $rows['proc_id'] .'\')">';
echo "<td>" .$rows['p_name'] . " " . $rows['p_surname']. " </td>";
echo "<td>" .$rows['p_from']. "</td>";  
echo "<td>" .$rows['p_where']. "</td>";
echo "<td>" .$rows['p_date']. "</td>";  
echo "<td>" .$rows['price']. "</td>";   
echo "<td>" .$rows['type']. "</td>";    
echo "</tr>";
}
                                        //display the links to the pages
for ($page=1; $page <= $num_of_pages; $page++) { 
echo '<a href="search.php?page=' .$page.' &from='.$from.' &where='.$where.' &date='.$date.' &type='.$type.' ">' . $page . '</a> ';
                                        }

?>
</table>
</div>
</section>


<script>
function content(ID){
window.open('procdetail.php?proc_id=' + ID, '_blank');
}

$(document).ready(function () {
$( "#datepicker" ).datepicker();
});
</script>)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等