beanymanuk Posted July 5, 2012 Share Posted July 5, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/ Share on other sites More sharing options...
smoseley Posted July 5, 2012 Share Posted July 5, 2012 Are you using a Javascript framework like jQuery or Prototype? Would make your life a bit easier. What do you have for the server-side thus far? Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/#findComment-1359346 Share on other sites More sharing options...
beanymanuk Posted July 5, 2012 Author Share Posted July 5, 2012 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; }); }); Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/#findComment-1359349 Share on other sites More sharing options...
smoseley Posted July 5, 2012 Share Posted July 5, 2012 Check out the jQuery ajaxForm plugin. It'll turn your regular form into an AJAX form with one line of code: http://jquery.malsup.com/form/ Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/#findComment-1359410 Share on other sites More sharing options...
beanymanuk Posted July 6, 2012 Author Share Posted July 6, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/#findComment-1359609 Share on other sites More sharing options...
smoseley Posted July 6, 2012 Share Posted July 6, 2012 Simple answer - use OR instead of AND, and use BETWEEN for dates. Post your PHP for more help. Quote Link to comment https://forums.phpfreaks.com/topic/265250-ajax-search-multiple-fields/#findComment-1359634 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.