doufendi9063 2015-08-30 07:32
浏览 37

如果设置了日期,则根据日期显示数据库中的数据,否则显示页面加载和页面刷新的所有记录

I want to display records from database based on date if date is set else I want to display all records from table

sent_log.php

<form action="sent_log.php" method="POST">      
    <label>From</label>
    <input type="text" name="from_date">

    <label>To</label>
    <input type="text" name="to_date">  

<input type="submit" value="Submit" name="submit">
</form>

PHP Code

if(isset($_POST['submit']) && !empty($_POST['submit'])) {
    if (isset($_POST['from_date'],$_POST['to_date']) && !empty($_POST['from_date']) && !empty($_POST['to_date'])) {

    // code for display record based on date selected        

    }
} else {
   // code for display all records
}

SEE FULL CODE HERE Note: Don't consider the error in the link, Because code contains mysqli statements, I just want to display code not to display output, The code working fine without any error in my local pc!

Now my problem is when I open sent_log.php following code block working fine

else {
       // code for display all records
}

And when I select 2 dates and hit submit button, the following code block working fine

 if(isset($_POST['submit']) && !empty($_POST['submit'])) {
    if (isset($_POST['from_date'],$_POST['to_date']) && !empty($_POST['from_date']) && !empty($_POST['to_date'])) {

    // code for display record based on date selected        

    }
} 

But when I refresh the page I want to display all records But Now the output not changed, It displays records based on dates I selected Last time

I am looking output like

Display All records when first time load sent_log.php and when I refresh sent_log.php

If I select 2 dates from form in sent_log.php, load records based on 2 dates then I click refresh button load all records

From the Internet, To avoid form resubmission, It will be achieve By using 3 methods: Redirect to self, Ajax, session

But I don't know how to apply these 3 methods to my case

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看