Jump to content

pagination help


adamlacombe

Recommended Posts

<?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 keep getting these errors:

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

 

the errors are coming from the setcookie lines. any idea why its spitting out that?

 

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

Header errors can explain everything you need to look at.  To much to re-type.

 

As for you paganation problems, if this line FAILS.

if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) {

 

Your limit will not be written to the query.  You need to move it out of the if statement, so it will be.

Link to comment
Share on other sites

hmmm okay thanks, but... I tried that and I got

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 247

 

this is what it looks like now:

	$qquery .= implode( ' AND ', $questions_criteria );
}
	$qquery .= ' )';
$total = mysql_num_rows(mysql_query($qquery));

 

I also tried:

	$qquery .= implode( ' AND ', $questions_criteria );
}
	$qquery = '$qquery )';
$total = mysql_num_rows(mysql_query($qquery));

 

 

 

EDIT:

okay never mind that... I fixed it in a way.. it will not show results, but the pagination seems like its working.

 

<?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 .= ' )';
}
	$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'); ?>

Link to comment
Share on other sites

Try it this way:

<?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 = $qquery . ' 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'); ?>

 

This insures that you are asking for the same thing in the result query, as in the query asking for a row count.

Link to comment
Share on other sites

anyone else understand what might be going wrong? I tried changing that bit of code to just 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>";
		}

 

and still it spits out an error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 264

Link to comment
Share on other sites

Already did that.. it spits out what it should

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 16 AND 36 LIMIT $skip, 2

 

I don't see anything wrong with it... do you?

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.