Jump to content

Ajax search multiple fields


beanymanuk

Recommended Posts

Hi I have no idea how to do this and Googled and not found much help

I have a search form below and I want the user to be able to search by as little or as much as they want using the fields by the fields.

I am searching just one table called players

I want it to be an ajax form and load the results below the form.

 

<fieldset id="search">
<legend>Search Players</legend>
	<form action="/search.php" method="post" name="searchplayers" id="searchplayers">
	<ol><label>First Name</label><input id="firstname" name="firstname"  type="text">
	<input id="lastname" name="lastname" type="text" style="float:right"><label style="float:right;">Last Name</label></ol>
	<ol>
		<label for="closetime">Registered between:</label>
		<input type="text" id="registereda" name="registereda" class="datetime-pick"/> -
		<input type="text" id="registeredb" name="registeredb" class="datetime-pick"/>
	</ol>
	<ol>
		<label for="actiontime">Last Login between:</label>
		<input type="text" id="lastlogina" name="lastlogina" class="datetime-pick"/> -
		<input type="text" id="lastloginb" name="lastloginb" class="datetime-pick"/>
	</ol>
	<ol>
		<label for="actiontime">Last Draw entered between:</label>
		<input type="text" id="lastdrawentereda" name="lastdrawentereda" value="<?=set_value('actiontime');?>" class="datetime-pick"/> -
		<input type="text" id="lastdrawenteredb" name="lastdrawenteredb" value="<?=set_value('actiontime');?>" class="datetime-pick"/>
	</ol>
	<input type="submit" id="searchsubmit" name="search" value="Search" />
</fieldset>

Link to comment
Share on other sites

I've got an existing website in development

Yes I'm using Javascript framework

 

/js/jquery-1.7.1.min.js

/js/jquery-ui-1.8.17.custom.min.js

 

I have this basic function so far just posting firstname into a div

But I know I need to post that off to the controller then to model etc

Then all the other fields need to do the same eventually

 

$(function() {


	// turn the href into a submit trigger
	  $("#searchplayers").click(function() {
	    $("#searchplayers").submit();
	    return false;
	  });

   // check the mobile number format and submit or return error
   $("#searchplayers").submit(function() {

	var firstname = $('[name=firstname]').val()
	var lastname = $('[name=lastname]').val()

	var registereda = $('[name=	registereda]').val()
    var registeredb = $('[name=	registeredb]').val()

	var lastlogins = $('[name=lastlogina]').val()
	var lastlogine = $('[name=lastloginb]').val()

	var lastdrawentereda = $('[name=lastdrawentereda]').val()
	var lastdrawenteredb = $('[name=lastdrawenteredb]').val()

	$("#searchresults").html(firstname);

		//$.post(
		//$("#searchplayers").attr("action"),
		//$("#searchplayers").serialize(),
		//function(data){
		//		$("#downloadnowinfo").html(data).show();
		//}
	//);

	return false;
    });


});

 

Link to comment
Share on other sites

I am making progress and have one field searching but how do I search using more than 1 field to search by and only the fields which have search criteria in.

eg search "Nick" & "Hill" returns Nick Hill

search "Hill" returns Nick Hill

search "Nick" & "Rob"  returns no results

 

Also I need to search between 2 dates which are stored in the database as datetime fields

 

Any help is muchly appreciated

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.