-1

I have a page search.php where I am displaying all the table data from mysql database, say for the sql code:

select * from employee;

I also have a search form name employee_search_form which is used to search for employee within a certain age group, like in the following code:

select * from employee where age between 30 and 40;

Till here the code works good. When I open search.php for first time it shows all employees. Later when I search for a particular range of employees it works too.

But how to reset the search.php to original, showing all employees again. I tried reloading page after searching between 30 and 40. But it still shows the employees between 30 and 40 only.

The code used for searching data is

if ( isset( $_POST['submit_filter'] )   )
{
        $results = mysql_query('select * from employee where age between 30 and 40')
}
else 
{
        $results = mysql_query('select * from employee')
}

where submit_filter is name of submit button. ( more check conditions would be added in future )

after this I am using while loop to print the table data.

How this problem have to be solved. Please suggest me how to come over with it. I am new to using php and html. Any suggestions are welcome.

sravan kumar
  • 583
  • 3
  • 11
  • 24
  • possible duplicate of [How to make a redirect in PHP?](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Funk Forty Niner May 18 '16 at 16:46
  • @majid -- added the code but skipped lines related connection to database and checking connection details and stuff. – sravan kumar May 18 '16 at 16:55
  • @ Fred -- I dont think its about redirect to other page or same page. Please read my query again and do ask me if something not clear instead of giving negative voting. Am new to using php and am not sure if it is to do with redirecting or create a button which would reset the page. Please do suggest or have a discussion before voting. Also have patience and give time to read and answer your queries. – sravan kumar May 18 '16 at 17:13
  • The codefragment you posted is really helpful! If your 'submit_filter' is set in the post-request, your search will be filtered, if it isn't, it's unfiltered. Hope I could clarify things for you. If not, well, the answer might be in the part of the code you skipped (like e.g. the form that actually sets the variables). Btw, one way to clear the postvariable would be to use a redirect, but don't try it if you don't think it will work! – Solarflare May 18 '16 at 18:21
  • Thank you for your reply Solarflare. Now got to understand in which direction I have to think inorder to resolve the problem – sravan kumar May 19 '16 at 08:34

1 Answers1

0

This may not be a perfect answer but I have got this problem solved by just adding a refresh button with following code at end of my php script. I have not used any headers or output buffering.

<form action="search.php" method="post" >

    <button type="submit" name="refresh_data" class="btn btn-success">Refresh Table Data</button>

</form>

When you press this button the page is again reloaded and displays all the table data.

Suggest me if it is right way of doing the things.

sravan kumar
  • 583
  • 3
  • 11
  • 24