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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.