php search

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
budabug
Forum Newbie
Posts: 8
Joined: Fri Sep 03, 2004 10:32 am

php search

Post 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.";
	       }
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply