Jump to content

age/year dropdown


adamlacombe

Recommended Posts

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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