|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'd really appreciate responses on how to do this:
I'm trying to select records based on multiple critera. $test is a variable that comes in from a form. $query2 = "SELECT * FROM trovemain WHERE (cata LIKE '%$test%')"; This is selecting anything that has $test anywhere in the field "cata". Two questions: 1. will this pick up fields that start or end with $test? 2. How can I do some logical operators like AND and OR. I'd like to use not just $test, but about 10-15 variables and select out records that have variableA AND variableB AND variableC OR variableD I can't figure out how to do this... your help is appreciated. |
|
#2
|
|||
|
|||
|
1. will this pick up fields that start or end with $test?
>> should do both 2. How can I do some logical operators like AND and OR. <? $searchlist=array("cat", "dog", "mouse"); $query="SELECT * from trovemain WHERE "; for($i=0;$i<count($searchlist); $i++) $query.="cata LIKE '%$searchlist[$i]%' OR "; $query=substr($query, 0 -3); // strip off last 'OR ' $query.=" order by some_column"; //run the query ?> You can make the $searchlist array an array of variables from the form. You could also include a radio button saying "Search by ALL terms" (AND) or "Search by ANY term" (OR) - this will give you the ability to choose AND or OR for your query syntax. |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Multiple Searches in MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|