My project has a script that allows users/admins to make search and fetch queries with some parameter they can choose.
For example: Search for people that work night shift under 21 age. The way I made it is:
In the page there are some default items, like a welcome page, some items from database as well. When the user/admin
selects the parameter in the dropbox and clicks "search", the query is executed and results are returned and dysplayed on same page.
the welcome message now disappears. Everything is fine to this point.
However, problem starts when I found the need to submit something that is in the search query itself.
For example, if I want to send the search results by email. Or worst, found a big problem when using a pagination system.
It seems that everytime a button is clicked, all the display from the search query vanishes, and returns to the initial page with the welcome message.
Same problem with the pagination, when a page number is clicked, it "cancels" all the search query as if it looses the query memory.
I think my problem could be in the conditionals I use for the search.:
Which is something like:
Code: Select all
....
<?php
if("Search" == $_POST['submit']){
$_age = FilterData($_POST['age']);
$_period = FilterData($_POST['period']);
if("" != $_age && "" != $_period){
$search=true;
$members = new Search($_age,$_period);
$members->AdminViewMembers();
$message = "The table is organized by age ". $_age . " and working period " . $_period;
?>
<?php AdminHeader()?>
<div id="Admin_maincol">
<h1>Manage Users</h1>
<br/>
<?php if(true == $search){
?>
<table>
<form method="post" action="<?php echo($_SERVER['PHP_SELF'])?>">
<tr>
<td> <input type="submit" class="button" id="submit" name="submit" value="Send"></td>
</form>
</tr>
<?php
//loop through data set
if($message) echo $message;
for($counter = 0;$counter < count($members->data);$counter++){ ?>
<tr>
<td>
<?php echo($members->data[$counter]['user']);?>
</td>
<td><?php echo($members->data[$counter]['name']);?></td>
<td><?php echo($members->data[$counter]['region']);?></td>
<td width="20px"><?php echo($members->data[$counter]['age']);?></td>
</tr>
</table>
<?php } ?>
<?php }else{ ?>
<div id="welc_msg">
WELCOME .... BLAH BLAH BLAH
</div>
<br>
<form method="post" action="<?php echo($_SERVER['PHP_SELF']);?>#users">
<table>
<tr>
<td><label for="age" class="form_txt">User Age</label></td>
<td><?php if($message_age){echo("<p class='error_msg'>{$message_age}</p>");}?>
<select name="age">
<option value="">Select age</option>
<option value="15">10-15 years </option>
<option value="18">15-18 years </option>
<option value="25">18-25 years </option>
<option value="35">25-35 years</option>
<option value="40">35-40 years </option>
<option value="50">40-50 years</option>
<option value="50+">More than 50 years</option>
</select>
</td>
</tr>
</table>
</form>
<?php AdminFooter(); ?>
the "$search" becomes " = false"; I dont know if i'm doing it the wrong way as I only have just a year of PHP .
Any help or clue will be much welcomed and appreciated,
Thanks in advance,
Mike Spider