Jump to content

Search Query


dfowler

Recommended Posts

Hey guys, I'm reworking some code that a friend of mine wrote for a company and having some troubles.  This is a search query that needs to be able to add more fields to narrow the search.  He wants it though so that as you add fields, it remembers what was in the previous field.  Right now with the code it will reload the page and just adds fields based on the counter.  The problem with that is each time the page reloads it gets rid of the data and options selected in the top fields.

 

I figured some AJAX could really be put into use here.  However, as I got started I hit a wall and I'm not sure where to go logically.  I was hoping somebody could help me clear some of the cobwebs.  Thanks for any help!

 

<form action="create_query.php" method="post" name="formAdd" id="formAdd">						
      <table border=1 class='tableclass' width='100%'>
            <tr>
                  <td>
                        <table  cellspacing="2" cellpadding="1" width="100%">
                              <tr>
		            <td align="left" height="0" valign="baseline" colspan='2'>
			    <!-- Add Criteria Form. -->
			    <?php
		                  if($_POST['counterForm']) {
				        // Remove Filter Here
					if($_GET['remove']) {
					      $p_counter=$_POST['counter'];
					      $postvalue=$p_counter-1;
					}
		                        // Add Filter Here.
					else {
					      $p_counter=$_POST['counter'];
					      $postvalue=$p_counter+1;
					}
				  } else {
				        if($_GET['remove']) {
					      $p_counter=$_POST['counter'];
					      $postvalue=$p_counter-1;
					} else {
					      $postvalue=0;
					}
				  } ?>						
				  <input type='hidden' name="counter" value='<?echo $postvalue?>'>
				  <input type='submit' name="counterForm" value="Add Criteria">
                                          <hr>							
			          <!-- End Criteria Form. -->						
			    </td>								
		      </tr>
		</table>
                  </td>
            </tr>
      </table>					
</form>
<form action="create_query.php" method="post" name="form1" id="form1">
<input type='hidden' name='repeatValue' value='<?echo $postvalue;?>'>
<table align="left" cellspacing="2" cellpadding="1" width="100%" class='txtblack'>			  
<tr>
	<td align="right"><strong>Search :</strong></td>
	<td align="left" colspan='2'>  </td>
</tr>
	<?php								
		if($_POST['submit']) {
			$loop=$_POST['repeatValue'];
		} else {
			$loop=$postvalue;
		}
		for($j=0;$j<=$loop;$j++) {
			echo '<div id="divid'.$j.'">';
	?>				
<tr>
	<td align="right"><strong>Category :</strong></td>
	<td align="left" colspan='2'> 					
		<?php echo '<select name="cmb_category'.$j.'">'; ?>
			<option value="firstname" selected>First Name</option>
			<option value="lastname">Last Name</option>
			<option value="membershiptype">Membership Type</option>
			<option value="address">Address</option>
			<option value="email">EMail</option>
			<option value="city">City</option>
			<option value="state">Province/State</option>
			<option value="zip">Postal Code</option>
			<option value="country">Country</option>
			<option value="telephone">Phone</option>
		</select>
		<?php echo '<select name="selection'.$j.'">'; ?>
			<option value="contains" selected>Contains</option>
			<option value="is">Is</option>
		</select>
		<?php 
			echo '<input type="text" name="txtSearch'.$j.'" value="'.$_POST['txtSearch'.$j].'">'; 
			echo '  <a href="create_query.php?remove=1" id="'.$j.'" >Remove</a>';
		?>
	</td>				  
</tr>
                <?php echo '</div>';
	}//for Loop CLose.
?>
<tr>
	<td colspan='3'><hr></td>
</tr>
<tr>
	<td align="left" colspan="3">
		<input type="submit" name="submit" value="Search"  />
		<input type="reset" name="reset" value="Reset"/>

 

Link to comment
https://forums.phpfreaks.com/topic/90759-search-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.