Page 1 of 1

php search

Posted: Mon Sep 13, 2004 3:45 pm
by budabug
this is what I have thus far in the code and it works for pulling up a search on association, but I also want it to search names and time. How do I add that in?

Code: Select all

mysql_select_db("timetracker");
	     	     
	   $searchoption = '';


	     
	     
	     #echo $searchoption;
         
         
	     #Determine how many candidates match the criteria
          
           $query = "SELECT * FROM time WHERE association = '".$association."' ".$searchoption." ORDER BY full_date DESC";
           $result = mysql_query($query);
           $num_results = mysql_num_rows($result);
           
	       if ($num_results == 0)
	       {
             echo "<b>There are no candidates that meet your criteria</b>.  Please your back button and broaden your search.";
	       }
	       elseif ($num_results == 1)
	       {
             echo "<b>There is one candidate that meets your criteria</b>.  ";
	       }
	       else 
	       {
             echo "<b>There are ".$num_results." candidates that meet your criteria</b>.  Results are sorted by submission date - the most recent submissions are at the top.";
	       }

Posted: Mon Sep 13, 2004 4:59 pm
by feyd
generally works like so:

Code: Select all

SELECT * FROM `table_name` WHERE `field1` LIKE '$field1search' OR `field2` LIKE '$field2search' ORDER BY `somefield`
you can switch the OR to AND dynamically, depending on options they choose in the search form.

this is now the 2nd time we've talked about this with you.