lovephp Posted May 27, 2015 Share Posted May 27, 2015 (edited) ok currently i use these below coding to load more results from database JS and HTML on index.php <script type="text/javascript"> $( document ).on( 'click', '.loadmore', function () { $(this).text('Loading...'); var ele = $(this).parent('li'); $.ajax({ url: 'load.php', type: 'POST', data: { page:$(this).data('page'), }, success: function(response){ if(response){ ele.hide(); $(".news_list").append(response); } } }); }); </script> /////////////////////////////////////////////////////////////////////////// <div id="container"> <ul class="news_list"> <?php $query=mysql_query("SELECT * FROM profiles WHERE Gender ='female' ORDER BY UserID DESC LIMIT 0 , $resultsPerPage"); while($data=mysql_fetch_array($query)){ $fname=$data['Fname']; $lname=$data['Lname']; echo "<table border='0'><tr><td><h3>$fname</h3></td><td>$lname</td></tr></table>"; } ?> <li class="loadbutton"><button class="loadmore" data-page="2">More Records...</button></li> </ul> </div> load.php <?php if(isset($_POST['page'])): $paged=$_POST['page']; $sql="SELECT * FROM profiles WHERE Gender ='female' ORDER BY UserID DESC"; if($paged>0){ $page_limit=$resultsPerPage*($paged-1); $pagination_sql=" LIMIT $page_limit, $resultsPerPage"; } else{ $pagination_sql=" LIMIT 0 , $resultsPerPage"; } $result=mysql_query($sql.$pagination_sql); $num_rows = mysql_num_rows($result); if($num_rows>0){ while($data=mysql_fetch_array($result)){ $fname=$data['Fname']; $lname=$data['Lname']; echo "<table border='0'><tr><td>$fname</td><td>$lname</td></tr></table>"; } } if($num_rows == $resultsPerPage){?> <li class="loadbutton"><button class="loadmore" data-page="<?php echo $paged+1 ;?>">More Records...</button></li> <?php }else{ echo "<li class='loadbutton'><span class='endload'> No More Data... </span></li>"; } endif; ?> what im trying to acheive is get search records the similar way when user submits the form on search.php then on the results.php few records show and when click on load more and more search records display. Anyone? Edited May 27, 2015 by lovephp Quote Link to comment Share on other sites More sharing options...
lovephp Posted May 31, 2015 Author Share Posted May 31, 2015 anyone? Quote Link to comment Share on other sites More sharing options...
jcbones Posted June 1, 2015 Share Posted June 1, 2015 You show no search form, nor do you show what you are trying to search for. It would be near impossible to suggest a solution. Quote Link to comment Share on other sites More sharing options...
lovephp Posted June 1, 2015 Author Share Posted June 1, 2015 (edited) You show no search form, nor do you show what you are trying to search for. It would be near impossible to suggest a solution. sorry bout that mate. ok here is my search.php which i include in the php pages <form action="results.php" method="post"> <select id="employment" name="employment" > <option value=" " disabled="disabled" selected="selected">Select Employment</option> <option value="Unemployed">Unemployed</option> <option value="Employed">Employed</option> <option value="Self Employed">Self Employed</option> <option value="Government Employed">Government Employed</option> </select>, <select id="maritalstatus" name="maritalstatus" > <option value=" " disabled="disabled" selected="selected">Select Marital Status</option> <option value="Never Married">Never Married</option> <option value="Married">Married</option> <option value="Awaiting Divorce">Awaiting Divorce</option> <option value="Divorced">Divorced</option> <option value="Widowed">Widowed</option> <option value="Annulled">Annulled</option> </select>, Age: <select name ='agefrom'> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25' s>25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> </select> to: <select name ='ageto'> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> <option value='25' selected="selected">25</option> <option value='26'>26</option> <option value='27'>27</option> <option value='28'>28</option> <option value='29'>29</option> <option value='30'>30</option> </select>, Height: <select name="Min_Height" id="Min_Height"> <option value="1">4' 0" (1.22 mts)</option> <option value="2">4' 1" (1.24 mts)</option> <option value="3">4' 2" (1.28 mts)</option> <option value="4">4' 3" (1.31 mts)</option> <option value="5">4' 4" (1.34 mts)</option> <option value="6">4' 5" (1.35 mts)</option> <option value="7">4' 6" (1.37 mts)</option> <option value="8">4' 7" (1.40 mts)</option> <option value="9">4' 8" (1.42 mts)</option> <option value="10">4' 9" (1.45 mts)</option> <option value="11">4' 10" (1.47 mts)</option> <option value="12">4' 11" (1.50 mts)</option> <option value="13">5' 0" (1.52 mts)</option> <option value="14">5' 1" (1.55 mts)</option> <option value="15">5' 2" (1.58 mts)</option> <option value="16">5' 3" (1.60 mts)</option> <option value="17">5' 4" (1.63 mts)</option> <option value="18">5' 5" (1.65 mts)</option> <option value="19">5' 6" (1.68 mts)</option> <option value="20">5' 7" (1.70 mts)</option> <option value="21">5' 8" (1.73 mts)</option> <option value="22">5' 9" (1.75 mts)</option> <option value="37">7' (2.13 mts) plus</option> </select> to: <select name="Max_Height" id="Max_Height"> <option value="1">4' 0" (1.22 mts)</option> <option value="2">4' 1" (1.24 mts)</option> <option value="3">4' 2" (1.28 mts)</option> <option value="4">4' 3" (1.31 mts)</option> <option value="5">4' 4" (1.34 mts)</option> <option value="6">4' 5" (1.35 mts)</option> <option value="7">4' 6" (1.37 mts)</option> <option value="8">4' 7" (1.40 mts)</option> <option value="9">4' 8" (1.42 mts)</option> <option value="10">4' 9" (1.45 mts)</option> <option value="11">4' 10" (1.47 mts)</option> <option value="12">4' 11" (1.50 mts)</option> <option value="13">5' 0" (1.52 mts)</option> <option value="14">5' 1" (1.55 mts)</option> <option value="15">5' 2" (1.58 mts)</option> <option value="16">5' 3" (1.60 mts)</option> <option value="17">5' 4" (1.63 mts)</option> <option value="18">5' 5" (1.65 mts)</option> <option value="19">5' 6" (1.68 mts)</option> <option value="20">5' 7" (1.70 mts)</option> <option value="21">5' 8" (1.73 mts)</option> <option value="22">5' 9" (1.75 mts)</option> <option value="37" selected="selected">7' (2.13 mts) plus</option> </select> <input type="submit" name="submit" value="Find" class="submit"> </form> then here comes the results.php which displays results accordingly <?php if(isset($_POST['submit'])){ $employment = mysql_real_escape_string($_POST['employment']); $mstatus = mysql_real_escape_string($_POST['mstatus']); $agefrom = mysql_real_escape_string($_POST['agefrom']); $ageto = mysql_real_escape_string($_POST['ageto']); $criteria = array(); if($employment !='') { $criteria[] = "Employment = '".$employment."'"; } if($mstatus !='') { $criteria[] = "Maritalstatus = '".$mstatus."'"; } if($agefrom !='' && $ageto !='') { $criteria[] = "YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '".$agefrom."' AND '".$ageto."'"; } $query = "SELECT * FROM profiles WHERE " . implode(' AND ', $criteria); $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo $age = userAge($dob= $row["dob"]).''; } } print_r($_POST); ?> like the first posted above i wish to have option to load just 5 search by default and then a button to load more results matching the selected criteria from search.php im not getting any idea how to achieve it Edited June 1, 2015 by lovephp Quote Link to comment Share on other sites More sharing options...
rwhite35 Posted June 1, 2015 Share Posted June 1, 2015 (edited) Assign your $criteria to a $_SESSION on initial load (the initial db pull). Then you only need to pass the page count (5, 10, 15, 20...) in the $_POST . session_start(); $_SESSION['criteria'] = $criteria; //assigned on initial results Then on your sub. query (BTW mysql_* is deprecated) which pulls the next five records, assign the "criteria" from the $_SESSION. if(isset($_SESSION['criteria']) && !empty($_SESSION['criteria'])) { //assign to local var if available $criteria = $_SESSION['criteria']; $sql="SELECT * FROM profiles WHERE Gender = $criteria['gender'] ORDER BY UserID DESC LIMIT 0 , $resultsPerPage"; } The Internet is "stateless" which requires your criteria to be stored in a container like a session, cookie or database in order to hold that current "criteria". hope that helps. Edited June 1, 2015 by rwhite35 Quote Link to comment Share on other sites More sharing options...
lovephp Posted June 1, 2015 Author Share Posted June 1, 2015 no hope bro it helped alot i got this done yay thanks a ton.. Quote Link to comment Share on other sites More sharing options...
lovephp Posted June 1, 2015 Author Share Posted June 1, 2015 there is an issue here i did it like this <?php if(isset($_POST['submit'])){ $employment = mysql_real_escape_string($_POST['employment']); $mstatus = mysql_real_escape_string($_POST['mstatus']); $agefrom = mysql_real_escape_string($_POST['agefrom']); $ageto = mysql_real_escape_string($_POST['ageto']); $criteria = array(); if($employment !='') { $criteria[] = "Employment = '".$employment."'"; } if($mstatus !='') { $criteria[] = "Maritalstatus = '".$mstatus."'"; } if($agefrom !='' && $ageto !='') { $criteria[] = "YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '".$agefrom."' AND '".$ageto."'"; } $_SESSION['criteria'] = $criteria; $query=mysql_query("SELECT * FROM profiles WHERE " . implode(' AND ', $criteria)." ORDER BY UserID DESC LIMIT 0 , $resultsPerPage"); while($data=mysql_fetch_array($query)){ $fname=$data['dob']; $lname=$data['Lname']; echo "<table border='0'> <tr> <td width='20%'> <img src='uploads/profiles/16022014045.jpg' class='loadimg'> </td> <td width='80%'> <h3>Balaswami Surraminiam</h3> <b>Age:</b> 60 <br/> <b>Caste:</b> $fname <br/> <b>Height:</b> 4' 5'' <br/> <b>Profession:</b> Chartered Accountant <br/> <b>Location:</b> Badarpur Rly Township <br/><br/> <a href='#'>view profile</a> </td> </tr> </table>"; } } print_r($_SESSION); ?> now when i select employment, mstatus and age anyways by default selected from 18 - 25 the query only outputs employment and age the mstatus does not show. what wrong am i doing here??? also the session outputs like this Array ( [criteria] => Array ( [0] => Employment = 'Government Employed' [1] => YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '18' AND '25' ) ) Quote Link to comment Share on other sites More sharing options...
lovephp Posted June 1, 2015 Author Share Posted June 1, 2015 there is an issue here i did it like this <?php if(isset($_POST['submit'])){ $employment = mysql_real_escape_string($_POST['employment']); $mstatus = mysql_real_escape_string($_POST['mstatus']); $agefrom = mysql_real_escape_string($_POST['agefrom']); $ageto = mysql_real_escape_string($_POST['ageto']); $criteria = array(); if($employment !='') { $criteria[] = "Employment = '".$employment."'"; } if($mstatus !='') { $criteria[] = "Maritalstatus = '".$mstatus."'"; } if($agefrom !='' && $ageto !='') { $criteria[] = "YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '".$agefrom."' AND '".$ageto."'"; } $_SESSION['criteria'] = $criteria; $query=mysql_query("SELECT * FROM profiles WHERE " . implode(' AND ', $criteria)." ORDER BY UserID DESC LIMIT 0 , $resultsPerPage"); while($data=mysql_fetch_array($query)){ $fname=$data['dob']; $lname=$data['Lname']; echo "<table border='0'> <tr> <td width='20%'> <img src='uploads/profiles/16022014045.jpg' class='loadimg'> </td> <td width='80%'> <h3>Balaswami Surraminiam</h3> <b>Age:</b> 60 <br/> <b>Caste:</b> $fname <br/> <b>Height:</b> 4' 5'' <br/> <b>Profession:</b> Chartered Accountant <br/> <b>Location:</b> Badarpur Rly Township <br/><br/> <a href='#'>view profile</a> </td> </tr> </table>"; } } print_r($_SESSION); ?> now when i select employment, mstatus and age anyways by default selected from 18 - 25 the query only outputs employment and age the mstatus does not show. what wrong am i doing here??? also the session outputs like this Array ( [criteria] => Array ( [0] => Employment = 'Government Employed' [1] => YEAR(FROM_DAYS(DATEDIFF(CURDATE(), dob))) BETWEEN '18' AND '25' ) ) Quote Link to comment 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.