Jump to content

sql "where" + "or"


blueman378

Recommended Posts

hmm my bad, i guess i should have checked first, its cause i had no idea that there was a OR in mysql, so i kinda put that together as i example, but it should work?

 

haha cool,

 

well i guess ill use this thread to ask my second question,

i have a search form which is a simple form,

<form name="search">
<input type="text" name="searchf">
<input type="submit" value="Search!">
</form>

 

what im looking for is a script which splits the words based on the space, it thencounts how many words there are and assigns them each a variable name "$search1" "$search2" ect,

 

i then need a small script which will check to see how many variables there are and will do what is listed above, adding as many ors as needed.

 

and one small modification to what i wanted before i actually wanted AND not OR, or if possible a AND/OR it searches based on priority, so the results which match the AND come above the OR

 

im assuming you would use explode on the " " character or something like that?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/80257-sql-where-or/#findComment-406747
Share on other sites

here you go just a rough sketch of things

 

<?php
if (isset($_POST['submitform']))
{

$strWords = $_POST['searchf'];
$strType = $_POST['type'];

$arrWords = explode(" ",$strWords);
$arrMatches = array();
foreach ($arrWords as $strKey =>  $strValue)
{
array_push($arrMatches," gName='$strValue' ");
}


$strSql = "SELECT * FROM games WHERE ".implode(" $strType ",$arrMatches) ." ORDER BY gName";

print $strSql;



}

?>

<form name="search" method="post">
<input type="text" name="searchf">
<select name="type">
<option value="AND">AND</option>
<option value="OR">OR</option>
</select>
<input type="submit" name="submitform" value="Search!">

</form>

Link to comment
https://forums.phpfreaks.com/topic/80257-sql-where-or/#findComment-406748
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.