Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Searching mysql through a form

    Hi Guys,

    i have 5 basic fields in a form, when submitted search mysql to give back results , but i'm having trouble with 1 of the fields its the search between specific ages for example: 20 and 50 give all the results back of the users between these ages

    code:

    PHP Code:
    <?php
      
    ## 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;
      
      }
      
    ?>
    and input would be appreciated

    Graham

  • #2
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    It looks to me like you've used incorrect variables.
    You've set $frage to equal $_GET['fromage'], but in the query you use a variable called $fromage. Were you intending to do that and $fromage has been set somewhere else that isn't shown in the current portion of the script? Same go's for $to and $toage.

    PHP Code:
    $searchquery .= " AND `year` BETWEEN YEAR(CURDATE() - INTERVAL $to YEAR) AND YEAR(CURDATE() - INTERVAL $frage YEAR)"

  • Users who have thanked fl00d for this post:

    graham23s (11-18-2007)

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    LOL damnn yep that was it, i was using other variables further up the script

    thanks for that mate

    Graham


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •