Jump to content

Searching mysql


graham23s

Recommended Posts

Hi Guys,

 

i have knocked up a basic for with 5 fields to search, i'm having trouble with the between ages selection:

 

code:

 

  ## deal with the submission
  if(isset($_GET['search'])) {
  
  echo ("<hr />"); 
  
  ## vars
   $gender = $_GET['gender'];
  $herefor = $_GET['herefor'];
  $country = $_GET['from'];
    $frage = $_GET['fromage'];
       $to = $_GET['toage']; 
       
       //echo $gender.$herefor.$from.$frage.$to;
       
  ## compile the query
  $searchquery  = "SELECT * FROM `users` ";
  $searchquery .= "WHERE `gender`='" . $gender . "' ";
  $searchquery .= "AND `herefor`='$herefor' ";
  $searchquery .= "AND `country`='$country'";
  $searchquery .= " AND `year` BETWEEN YEAR(CURDATE() - INTERVAL $toage YEAR) AND YEAR(CURDATE() - INTERVAL $fromage YEAR)";
  
  ## run query
  $resultquery = mysql_query($searchquery);
  
  ## num results
  $numresults = mysql_num_rows($resultquery);
  
  echo $numresults;
  
  }

 

when the user selects between 18 and 50 for example, i assume thats where the problem lies is there a better way to do that all?

 

thanks guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/77819-searching-mysql/
Share on other sites

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.