Jump to content

search for a string within an array


laurajohn89

Recommended Posts

I have checkboxes that users select to search for particular types of events.  If a user selects dressage on its own, records with just type dressage in are returned.  I want it so that if a user selects dressage, all records that contain the word dressage in are returned.

 

Sorry its hard to explain. 

 

The search page:

 

<form action="results.php" method="post">
<table> <tr><td>Type of Event: </td> </tr>
<tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="combinedtraining" value="Combined Training" />Combined Training</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="dressage" value="Dressage" />Dressage</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="demostrials" value="Demos/trials" />Demos / Trials</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="driving" value="Driving" />Driving</p></td> </tr>
<tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="endurance" value="Endurance" />Endurance</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="eventing" value="Eventing" />Eventing</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="exracehorseclasses" value="Ex-Racehorse Classes" />Ex-Racehorse Classes</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="funsponsored" value="Fun / Sponsored" />Fun / Sponsored</p></td> </tr>
<tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="hunting" value="Hunting" />Hunting</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="jumpcross" value="Jumpcross" />Jumpcross</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="ride" value="Ride" />Ride</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="saleauction" value="Sale / Auction" />Sale / Auction</p></td> </tr>
<tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="showjumping" value="Show Jumping" />Show Jumping</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="showsmixeddiscplins" value="Shows / Mixed Discplins" />Shows / Mixed Discplins</p></td>
<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="trainingclinic" value="Training Clinic" />Training Clinic</p></td> 
	<td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="trec" value="Trec" />Trec</p></td> </tr>
<tr> <td width="25%"><p class="contentclass"><input type="checkbox" name="type[]" id="other" value="Other" />Other</p></td> </tr>
<tr><td><input type="submit" name="submit" value="Submit"/></td></tr> </table>	
</form>	

 

results.php page:

 

$type = implode(",",$_POST['type']);

if(!isset($_POST['type'])){
	$sql = mysql_query("select * from events where type='".$type."'");
    }
else 
$sql = mysql_query("select * from events");

 

 

I need something like:

if $type contains dressage

select * from events where type '%dressage%'

 

Many thanks

Link to comment
https://forums.phpfreaks.com/topic/198252-search-for-a-string-within-an-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.