Pikachu2000 Posted March 22, 2011 Share Posted March 22, 2011 For the time being, with few records in the tables, it probably won't be a big deal. But it should be rewritten to be more efficient before the tables get too large. I'll look at it again when I have time a little later today. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191071 Share on other sites More sharing options...
adamlacombe Posted March 22, 2011 Author Share Posted March 22, 2011 okay cool, thanks man. You can just PM me it later if this topic gets old and lost Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191072 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 Finally had time to sit down and look at this again. Here's what I came up with. This is all of the code from if( isset($_POST['submit']) ) { to the end of the script. I added a couple comments in the code, but if you need any clarification, let me know. Â Keep in mind, you haven't added any form field validation, so that should be considered, as well as maybe making the form 'sticky' so the user's choices stay in the form fields after the form has been submitted. Â if( isset($_POST['submit']) ) { $first = clean_up($_POST['first']); $last = clean_up($_POST['last']); $smoke = clean_up($_POST['smoke']); $drink = clean_up($_POST['drink']); $gender = clean_up($_POST['gender']); $age_from = clean_up($_POST['age_from']); $age_to = clean_up($_POST['age_to']); $orientation = clean_up($_POST['orientation']); $religious = clean_up($_POST['religious']); $ethnicity = clean_up($_POST['ethnicity']); $query = "SELECT `id`, `first`, `last`, `avatar`, `gender`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $query .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $query .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' ) { $query .= ' AND id IN( SELECT `user_id` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } $query .= implode( ' AND ', $questions_criteria ); $query .= ' )'; } echo "<table width='100%' align='center'> <div class='content'> Search users results for: $keyword <br />"; echo "<br>$query</br>"; if(mysql_num_rows($r3) == "0"){ echo "sorry there are no results"; } while( $rr3=mysql_fetch_array($r3) ) { $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); echo "<a href='index.php?action=profile&id=$user'><img src='avatars/$avatar' width='41' height='41' /> $first $last</a><hr>"; } echo "</div></table>"; echo "</div>"; } include ('footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191757 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 Here is what I have now <?php $title="Search"; $metakeywords="search, find"; $metadescription="Search for your love!"; include ('header.php'); echo ' <table width="100%"><tr><td valign="top" class="content">       <form action="index.php?action=search" method="post">          <b>Seeking Gender</b>          <select name="gender">           <option value="">Either</option>           <option value="Male">Male</option>           <option value="Female">Female</option>          </select> <hr>          <b>Smoke?</b>          <select name="smoke">           <option value="">Doesn\'t matter</option>           <option value="Yes">Yes</option>           <option value="No">No</option>          </select> <hr>          <b>Drink?</b>          <select name="drink">           <option value="">Doesn\'t matter</option>           <option value="Yes">Yes</option>           <option value="No">No</option>          </select> <hr>          <b>Body Type </b>          <select name="bodytype">           <option value="">Doesn\'t matter</option> <option value="Slim / Slender">Slim / Slender</option> <option value="Athletic">Athletic</option> <option value="Average">Average</option> <option value="Some extra baggage">Some extra baggage</option> <option value="Body builder">Body builder</option>          </select> </td><td valign="top" class="content">          <b>First Name</b> <input type="text" name="first" size="17"><br> <b>Last Name</b><input type="text" name="last" size="17"> <hr> <b>Sexual orientation</b>        <select class="orientation" name="orientation">        <option value="">Any</option> <option value="Bi">Bi</option> <option value="Gay/Lesbian">Gay/Lesbian</option> <option value="Straight">Straight</option>          </select> <hr>          <b>Age Range</b>          <select class="date" name="age_from">'; $years = range( 16, 100 ); foreach( $years as $v ) {   echo "<option value=\"$v\">$v</option>\n"; } echo '          </select> to          <select class="date" name="age_to">'; $years = range( 16, 100 ); foreach( $years as $v ) {   echo "<option value=\"$v\">$v</option>\n"; } echo '</select></td><td valign="top" class="content"> <b>Religion</b>        <select name="religious">        <option value="">Any</option> <option value="Agnostic">Agnostic</option> <option value="Atheist">Atheist</option> <option value="Buddhist">Buddhist</option> <option value="Catholic">Catholic</option> <option value="Christian">Christian</option> <option value="Hindu">Hindu</option> <option value="Jewish">Jewish</option> <option value="Mormon">Mormon</option> <option value="Muslim">Muslim</option> <option value="Other">Other</option> <option value="Protestant">Protestant</option> <option value="Satanist">Satanist</option> <option value="Scientologist">Scientologist</option> <option value="Taoist">Taoist</option> <option value="Wiccan">Wiccan</option>          </select> <hr> <b>Ethnicity</b>        <select name="ethnicity">        <option value="">Any</option> <option value="Asian">Asian</option> <option value="Black / African descent">Black / African descent</option> <option value="East Indian">East Indian</option> <option value="Latino / Hispanic">Latino / Hispanic</option> <option value="Middle Eastern">Middle Eastern</option> <option value="Native American">Native American</option> <option value="Pacific Islander">Pacific Islander</option> <option value="White / Caucasian">White / Caucasian</option> <option value="Other">Other</option>          </select> <hr>          <br><input type="submit" name="submit" value="Search" /></form> </td></tr></table>'; if($_POST['submit']){ $first = clean_up($_POST['first']); $last = clean_up($_POST['last']); $smoke = clean_up($_POST['smoke']); $drink = clean_up($_POST['drink']); $gender = clean_up($_POST['gender']); $age_from = clean_up($_POST['age_from']); $age_to = clean_up($_POST['age_to']); $orientation = clean_up($_POST['orientation']); $religious = clean_up($_POST['religious']); $ethnicity = clean_up($_POST['ethnicity']); $bodytype = clean_up($_POST['bodytype']); $query = "SELECT `id`, `first`, `last`, `avatar`, `gender`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $query .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $query .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { $query .= ' AND id IN( SELECT `user_id` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } if( !empty($bodytype) ) { $questions_criteria[] = "`body_type` = '$bodytype'"; } $query .= implode( ' AND ', $questions_criteria ); $query .= ' )'; } echo "<table width='100%' align='center'>"; if(mysql_num_rows(mysql_query($query)) == "0"){ echo "sorry there are no results"; } while($rr3=mysql_fetch_array(mysql_query($query))){ $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); $about=clean_up($rr3[about]); echo "<tr><td valign='top' width='140' class='content'><center><img src='avatars/thumb/$avatar' /><br><a href='index.php?action=profile&id=$user'> $first $last</a></center></td><td class='content' valign='top'>".limitdesc($about)."</td></tr>"; } echo "</div></table>"; echo "</div>"; } include ('footer.php'); ?>  When I search, the results spit out thousands of double results. What am I supposed to do with the query? I used mysql fetch array but I guess the query is already an array. idk lol Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191785 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 Is this script included in another script that has loop running in it? Â I don't initially see any reason for double results, but first try changing the query's fetch function from mysql_fetch_array() to mysql_fetch_assoc() and see if that has any effect. If it doesn't, echo the query string, and paste it in to phpMyAdmin (or whatever you use) and see what results are returned there. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191801 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 Okay I tried changing it to mysql_fetch_assoc() and its still spitting out same exact profile again and again non stop.  I echoed it and I got this: SELECT `id` , `first` , `last` , `avatar` , `gender` , ( ( DATE_FORMAT( CURDATE( ) , '%Y' ) - DATE_FORMAT( `bdate` , '%Y' ) ) - ( DATE_FORMAT( CURDATE( ) , '00-%m-%d' ) < DATE_FORMAT( `bdate` , '00-%m-%d' ) ) ) AS age FROM `users` WHERE ( ( DATE_FORMAT( CURDATE( ) , '%Y' ) - DATE_FORMAT( `bdate` , '%Y' ) ) - ( DATE_FORMAT( CURDATE( ) , '00-%m-%d' ) < DATE_FORMAT( `bdate` , '00-%m-%d' ) ) ) BETWEEN 16 AND 35  I ran it inside of PHPMyAdmin and it gave me three account but non were copied over and over again. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191804 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 hmm I think its caused because of the implode. Never worked with that function before.. maybe there is something else we could do instead of using implode to see if that fixes it? Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191866 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 Nah, there's something else going on. Since you can echo the query and it executes in phpMyAdmin without exhibiting those symptoms, that rules out the implode()s being the cause. Are you sure it isn't somehow inside of a loop accidentally? Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191872 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 well its in a while() would that affect it? Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191876 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 If you mean the entire query is also in a while loop, yes, that would definitely do it . . . Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191877 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 no no just like this: Â while($rr3=mysql_fetch_array(mysql_query($query))){ $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); $about=clean_up($rr3[about]); echo "<tr><td valign='top' width='140' class='content'><center><img src='avatars/thumb/$avatar' /><br><a href='index.php?action=profile&id=$user'> $first $last</a></center></td><td class='content' valign='top'>".limitdesc($about)."</td></tr>"; } Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191879 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 Yup, that's it. I didn't notice that looking at the code on my phone. Try replacing all of the code between the two lines I commented out with this code. It's really better practice to have the query string separate from the query execution, and the execution separate from the fetch_* anyhow. Throwing it all together makes debugging query problems miserable. Note that the trigger_error() can be commented out unless/until you go live and start logging errors. Â // echo "<table width='100%' align='center'>"; if( $result = mysql_query( $query ) ) { if( mysql_num_rows($result) > 0 ) { while( $rr3 = mysql_fetch_assoc($result) ) { $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); $about=clean_up($rr3[about]); echo "<tr><td valign='top' width='140' class='content'><center><img src='avatars/thumb/$avatar' /><br><a href='index.php?action=profile&id=$user'> $first $last</a></center></td><td class='content' valign='top'>".limitdesc($about)."</td></tr>"; } } else { echo '<tr><td colspan="2">Sorry, your search returned no results.</td></tr>'; } } else { echo '<tr><td colspan="2">We\'re sorry, there has been an error processing your request. Please try later.</td></tr>'; trigger_error( "DB query: $query failed with error: " . mysql_error() . ' in ' . __FILE__ . ' on line: ' . __LINE__); } echo "</div></table>"; echo "</div>"; } //include ('footer.php'); ?> Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191898 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 Works like a charm Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191903 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 you're going to shoot me... How am I supposed to use pagination when the data is POST not GET? I'm sure its something simple I just can't put my finger on it. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191910 Share on other sites More sharing options...
Pikachu2000 Posted March 24, 2011 Share Posted March 24, 2011 You can use hidden fields or store data in $_SESSION vars, or you can just change the form method and variables to $_GET. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191917 Share on other sites More sharing options...
adamlacombe Posted March 24, 2011 Author Share Posted March 24, 2011 I decided to use cookies instead.  I put the pagination all together also, now I copied the entire query and pasted it above the other. I had to name it something different so I just called it qquery. I had to do that because I needed the number of rows before it gets LIMIT. Thats all correct.. i did that all right, correct? lol  <?php $title="Search"; $metakeywords="search, find"; $metadescription="Search for your love!"; include ('header.php'); $getpage=clean_up($_GET['page']); $getpage = abs((int) ($getpage)); echo ' <table width="100%"><tr><td valign="top" class="content">       <form action="index.php?action=search" method="post">          <b>Seeking Gender</b>          <select name="gender">           <option value="">Either</option>           <option value="Male">Male</option>           <option value="Female">Female</option>          </select> <hr>          <b>Smoke?</b>          <select name="smoke">           <option value="">Doesn\'t matter</option>           <option value="Yes">Yes</option>           <option value="No">No</option>          </select> <hr>          <b>Drink?</b>          <select name="drink">           <option value="">Doesn\'t matter</option>           <option value="Yes">Yes</option>           <option value="No">No</option>          </select> <hr>          <b>Body Type </b>          <select name="bodytype">           <option value="">Doesn\'t matter</option> <option value="Slim / Slender">Slim / Slender</option> <option value="Athletic">Athletic</option> <option value="Average">Average</option> <option value="Some extra baggage">Some extra baggage</option> <option value="Body builder">Body builder</option>          </select> </td><td valign="top" class="content">          <b>First Name</b> <input type="text" name="first" size="17"><br> <b>Last Name</b><input type="text" name="last" size="17"> <hr> <b>Sexual orientation</b>        <select class="orientation" name="orientation">        <option value="">Any</option> <option value="Bi">Bi</option> <option value="Gay/Lesbian">Gay/Lesbian</option> <option value="Straight">Straight</option>          </select> <hr>          <b>Age Range</b>          <select class="date" name="age_from">'; $years = range( 16, 100 ); foreach( $years as $v ) {   echo "<option value=\"$v\">$v</option>\n"; } echo '          </select> to          <select class="date" name="age_to">'; $yyears = range( 17, 100 ); foreach( $yyears as $v ) {   echo "<option value=\"$v\">$v</option>\n"; } echo '</select> </td><td valign="top" class="content"> <b>Religion</b>        <select name="religious">        <option value="">Any</option> <option value="Agnostic">Agnostic</option> <option value="Atheist">Atheist</option> <option value="Buddhist">Buddhist</option> <option value="Catholic">Catholic</option> <option value="Christian">Christian</option> <option value="Hindu">Hindu</option> <option value="Jewish">Jewish</option> <option value="Mormon">Mormon</option> <option value="Muslim">Muslim</option> <option value="Other">Other</option> <option value="Protestant">Protestant</option> <option value="Satanist">Satanist</option> <option value="Scientologist">Scientologist</option> <option value="Taoist">Taoist</option> <option value="Wiccan">Wiccan</option>          </select> <hr> <b>Ethnicity</b>        <select name="ethnicity">        <option value="">Any</option> <option value="Asian">Asian</option> <option value="Black / African descent">Black / African descent</option> <option value="East Indian">East Indian</option> <option value="Latino / Hispanic">Latino / Hispanic</option> <option value="Middle Eastern">Middle Eastern</option> <option value="Native American">Native American</option> <option value="Pacific Islander">Pacific Islander</option> <option value="White / Caucasian">White / Caucasian</option> <option value="Other">Other</option>          </select> <hr> <b>Children</b>        <select name="children">        <option value="">Doesn\'t matter</option> <option value="I don\'t want kids">I don\'t want kids</option> <option value="Love kids, but not for me">Love kids, but not for me</option> <option value="Undecided">Undecided</option> <option value="Someday">Someday</option> <option value="Expecting">Expecting</option> <option value="Proud parent">Proud parent</option>          </select> <hr> <b>Education</b>        <select name="education">        <option value="">Doesn\'t matter</option> <option value="High school">High school</option> <option value="Some college">Some college</option> <option value="In college">In college</option> <option value="College graduate">College graduate</option> <option value="Grad / professional school">Grad / professional school</option> <option value="Post grad">Post grad</option>          </select>          <br><input type="submit" name="submit" value="Search" /></form> </td></tr></table>'; if($_POST['submit'] || $_GET['page'] > "0"){ $first = clean_up($_POST['first']); $last = clean_up($_POST['last']); $smoke = clean_up($_POST['smoke']); $drink = clean_up($_POST['drink']); $gender = clean_up($_POST['gender']); $age_from = clean_up($_POST['age_from']); $age_to = clean_up($_POST['age_to']); $orientation = clean_up($_POST['orientation']); $religious = clean_up($_POST['religious']); $ethnicity = clean_up($_POST['ethnicity']); $bodytype = clean_up($_POST['bodytype']); $children = clean_up($_POST['children']); $education = clean_up($_POST['education']); if(!$_GET['page']){ if(!$first == ""){ setcookie("first", $first, time()+3600); } if(!$last == ""){ setcookie("last", $last, time()+3600); } if(!$smoke == ""){ setcookie("smoke", $smoke, time()+3600); } if(!$drink == ""){ setcookie("drink", $drink, time()+3600); } if(!$gender == ""){ setcookie("gender", $gender, time()+3600); } if(!$age_from == ""){ setcookie("age_from", "$age_from", time()+3600); } if(!$age_to == ""){ setcookie("age_to", "$age_to", time()+3600); } if(!$orientation == ""){ setcookie("orientation", $orientation, time()+3600); } if(!$religious == ""){ setcookie("religious", $religious, time()+3600); } if(!$ethnicity == ""){ setcookie("ethnicity", $ethnicity, time()+3600); } if(!$bodytype == ""){ setcookie("bodytype", $bodytype, time()+3600); } if(!$children == ""){ setcookie("children", $children, time()+3600); } if(!$education == ""){ setcookie("education", $education, time()+3600); } } $qquery = "SELECT `id`, `first`, `last`, `avatar`, `gender`, `about`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $qquery .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $qquery .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { $qquery .= ' AND id IN( SELECT `userid` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } if( !empty($bodytype) ) { $questions_criteria[] = "`body_type` = '$bodytype'"; } if( !empty($children) ) { $questions_criteria[] = "`children` = '$children'"; } if( !empty($education) ) { $questions_criteria[] = "`education` = '$education'"; } $qquery .= implode( ' AND ', $questions_criteria ); $qquery .= ' )'; } $total = mysql_num_rows(mysql_query($qquery)); $page_count = ceil($total / 2); $page = 1; if (isset($getpage) && $getpage >= 1 && $getpage <= $page_count) {   $page = (int)$getpage; } $skip = ($page - 1) * 2; $query = "SELECT `id`, `first`, `last`, `avatar`, `gender`, `about`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $query .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $query .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { $query .= ' AND id IN( SELECT `userid` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } if( !empty($bodytype) ) { $questions_criteria[] = "`body_type` = '$bodytype'"; } if( !empty($children) ) { $questions_criteria[] = "`children` = '$children'"; } if( !empty($education) ) { $questions_criteria[] = "`education` = '$education'"; } $query .= implode( ' AND ', $questions_criteria ); $query .= ' LIMIT $skip, 2 )'; } echo "<table width='100%' align='center'>"; if( $result = mysql_query( $query ) ) { if( mysql_num_rows($result) > 0 ) { while( $rr3 = mysql_fetch_assoc($result) ) { $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); $about=clean_up($rr3[about]); echo "<tr><td valign='top' width='140' class='content'><center><img src='avatars/thumb/$avatar' /><br><a href='index.php?action=profile&id=$user'> $first $last</a></center></td><td class='content' valign='top'>".limitdesc($about)."</td></tr>"; } } else { echo '<tr><td colspan="2">Sorry, your search returned no results.</td></tr>'; } } else { echo '<tr><td colspan="2">We\'re sorry, there has been an error processing your request. Please try later.</td></tr>'; } echo "</table>"; echo "<div class='content'><center>"; if($getpage == 0 || $getpage == 1){}else{  $plink = $getpage - 1;  echo "   <a href='index.php?action=search&page=$plink'>Previous</a>    "; } echo "<select id='ddp' onchange='document.location=(ddp.value)'> <option value=''>Page #</option>"; for ($i = 1; $i <= $page_count; ++$i){   echo ' <option value="index.php?action=search&page=' . $i . '">' . $i . '</option>'; } echo "</select>"; if($getpage == $page_count){}else{ if($page_count>1){ if($getpage == 0){  echo "    <a href='index.php?action=search&page=2'>Next</a>    "; }else{  $nlink = $getpage + 1;  echo "    <a href='index.php?action=search&page=$nlink'>Next</a>    "; } } } echo "</center></div>"; } include ('footer.php'); ?>  I am getting these errors when I search: Warning: Cannot modify header information - headers already sent by (output started at /home/gamersgo/public_html/datingsnap.com/header.php:4) in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 182 Warning: Cannot modify header information - headers already sent by (output started at /home/gamersgo/public_html/datingsnap.com/header.php:4) in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 183 those lines are the cookies and when I search, the results don't come out to two results per page. so the pagination isn't working right and i am getting those errors. any ideas? Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1191947 Share on other sites More sharing options...
adamlacombe Posted March 25, 2011 Author Share Posted March 25, 2011 I know I have to add the $_COOKIEs in to the query but I still don't get why it isn't limiting it to 2 results... and still can't figure out about the setting cookies. Link to comment https://forums.phpfreaks.com/topic/231269-ageyear-dropdown/page/3/#findComment-1192302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.