Jump to content

age range search from one colum! have a clue but cant quite put it together.


antonyfal

Recommended Posts

Im trying to create an age range search for my site, from one age column--

 

heres start of my query, and then im stuck with the html side:

 

// i have already setup the min and max from a mysql fetch from the same column "age"

 

$min=$dropdownlistmin

$max=$dropdownlistmax

 

SELECT age FROM profile_age WHERE age >= $min AND age <= $max;  // and now what do i do next?

 

any help please. Thanks.

 

$min=$dropdownlistmin
$max=$dropdownlistmax

$query = mysql_query("SELECT age FROM profile_age WHERE age >='$min' AND age <= '$max'");
while($row = mysql_fetch_array($query)) {
echo $row['age']."<br />";
}

heres my full code:

// at the moment i only have a search by age function, but i would like to change it to a search by age range function..  How can i add the $min and $max to this query below?

// note: i also have a class file and a html output page..

Im thinking i would need to get the mindropdown and max dropdown into this query?..

Please somebody assist me with this code..

rgs.

my current call to get dropdownlist values:

 

 

			if (in_array("age",$searchOptions)&& $showSearchOptions ) 
			{
			if (empty($sch->filter['age']) )
				$selectOption=$output['LANGUAGE_SEARCH_AGE'];
			else
				$selectOption=$sch->filter['age'];
			$showButton=true;				
		$query = "SELECT DISTINCT profile_age FROM #__sites_profiles WHERE  published = '1' ORDER BY profile_age ASC";
		$ageals=doSelectSql($query);			
		$agedropDownList ="<select class=\"inputbox\" name=\"age\">";
	    $agedropDownList .= "<option value=\"\">All</option>";
		foreach ($ageals as $ageal)
			{
		$selected="";
			$profile_age=$ageal->profile_age;
			$agedropDownList .= "<option ".$selected." value=\"".$profile_age."\">".$profile_age."</option>";
			}
		$agedropDownList.="</select>";
		$output['AGE']=$agedropDownList;
			}


and here is my class file search function:

function sitesSearch_age()
	{
	$filter=$this->filter['age'];
	$this->makeOrs();
	$profile_ors=$this->ors;
	if(!empty($filter) && $profile_ors )
		{
		$keywords= mysql_real_escape_string($filter);
		$ageals = explode( ' ', $keywords );
		$wheres = array();
		foreach ($ageals as $age)
			{
			$wheres2[] = "LOWER(profile_age) LIKE '%$age%'";
			$wheres[] = implode( ' OR ', $wheres2 );
			}
		$where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
		$query="SELECT profiles_uid FROM #__sites_profiles ";
		$query.=" WHERE ( $where ) ";
		$query.=" $profile_ors AND published = '1' ";
		$this->resultBucket=doSelectSql($query);
		}
	else
		$this->resultBucket=array();
	$this->sortResult();
	}

Archived

This topic is now archived and is closed to further replies.

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