#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    I am kinda new so I don't really know what's wrong. It is a small search engine for a job site using PHP and MySQL. I want to be able to search by one, two, or all three fields. Thanks
    //code//

    IF ($salary == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (employmenttype = '$employmenttype' and jobtype = '$jobtype') ORDER BY jobnumber desc",$db);
    ELSEIF ($jobtype == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (employmenttype = '$employmenttype' and salary = '$salary') ORDER BY jobnumber desc",$db);
    ELSEIF ($employmenttype == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (jobtype = '$jobtype' and salary = '$salary') ORDER BY jobnumber desc",$db);
    ELSEIF ($employmenttype == 'any' and $jobtype == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (salary = '$salary') ORDER BY jobnumber desc",$db);
    ELSEIF ($employmenttype == 'any' and $salary == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (jobtype = '$jobtype') ORDER BY jobnumber desc",$db);
    ELSEIF ($jobtypetype == 'any' and $salary == 'any') :
    $result = mysql_query("SELECT * FROM kj WHERE (employmenttype = '$employmenttype') ORDER BY jobnumber desc",$db);
    ELSE :
    $result = mysql_query("SELECT * FROM kj WHERE (employmenttype = '$employmenttype' and jobtype = '$jobtype' and salary = '$salary') ORDER BY jobnumber desc",$db);
    ENDIF;
    //code//

  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Are you using text fields or drop downs? If drop downs set the value for option 'any' to '' (empty field). Then in your target script:

    <?
    if (empty($salary)&&empty($employmenttype)&&empty($jobtype)
    {
    // return to form telling them to specify at least 1 catagory
    exit;
    }
    $query="select * from kb where(";
    if ($salary) $queryadd[]="salary='$salary'";
    if ($employmenttype) $queryadd[]="employmenttype='$employmenttype'";
    if ($jobtype) $queryadd[]="jobtype='$jobtype'";
    $query.=$queryadd[0];
    for ($i=1;$i<count($queryadd);$i++)
    {
    $query.=" and ".$queryadd[$i];
    }
    $query.=") order by jobnumber desc";
    $result=mysql_query($query);
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    I am using drop downs. You can see it at http://www.alltexan.com/atgraphics/k/jobsearch.php3. This sends it to http://www.alltexan.com/atgraphics/k...hresults.php3. When I tried the script it didn't work. I want it so that you can search by only the fields you want out of the 3(or by all).I could do it with multiple result scripts(but of course I don't want that). Thanks for the help.
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    If you want help you'll have to provide more information then "When I tried the script it didn't work."

    What error did you get? If no error did you get unexpected results?
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    With the code I had if you specified one 'any' it would work but when you try to use 2 'any' so that you are just searching with one criteria it says that it didn't find any results(but it should). I guess I need help on the "ELSEIF ($employmenttype == 'any' and $jobtype == 'any')" part. I tried the following but it didn't work either: ELSEIF ($employmenttype and $jobtype == 'any') I don't get any errors so I don't know what's wrong. Thanks
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Did you try the script I provided? If so, what were the results?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    4
    Rep Power
    0
    When I tried yours it would work if I specified all 3 fields. When I left the field as '' instead of 'any' the get url would look like this : newsearchresults.php3?jobtype=&employmenttype=Full+Time&salary=N%2FA&submit=Submit
    It wouldn't get any results but it should.
  14. #8
  15. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Are you sure N/A is a valid entry? If you used a binary field and in the table it is n/a it won't match.

    You're going to have to do some testing. Print out some variables here and there, particularly the query string to see if it is being "built" correctly. If it looks ok, cut and paste it into the command line for a direct query on mysql.

Similar Threads

  1. Frames hijacked after remote search
    By Telejoke in forum Antivirus Protection
    Replies: 2
    Last Post: September 26th, 2007, 09:32 AM
  2. Replies: 4
    Last Post: February 13th, 2005, 11:58 PM
  3. Cgi Search feature script
    By butsy_7 in forum Perl Programming
    Replies: 5
    Last Post: January 22nd, 2004, 07:43 PM
  4. Is there any alternative to fulltext search?
    By irishairpics in forum MySQL Help
    Replies: 2
    Last Post: December 10th, 2003, 02:40 PM
  5. Site html search with php?
    By stojan in forum PHP Development
    Replies: 1
    Last Post: November 17th, 2003, 09:20 PM

IMN logo majestic logo threadwatch logo seochat tools logo