CoderZone.org

Category: >> PHP Code >> Search All Words Of A String In mySQL Bookmark and Share

<< lastnext >>

Snippet Name: Search All Words Of A String In mySQL

Description: This code will break a string of words up along the spaces and do a mySQL search for each of the words in the string.

Also see:
» SEO string generator
» Match all #RRGGBB or #RGB values i...
» Remove empty lines from a string o...
» Find first non-numeric character i...
» Read a web page directly in to a s...
» Multi-line variables and strings i...
» Convert a String to Title Case in ...
» Count all words in a string
» Count specific characters in a str...
» Create an array from comma separat...
» Convert Unix time string to a date...
» Count Uppercase Letters In A String
» Search and Replace On Every Field ...
» Neatly trim a string to a set numb...
» Search array elements for a substr...
» Add a period at the end of a strin...
» Count capital letters in a string
» Remove Extra Spaces From A String
» Get Query String with Javascript
» Create string by formatting an amo...
» Search PL/SQL for a string/ key va...
» INSTR (InString)
» SUBSTR (SubString)
» Generate unique strings of random ...
» String Functions: REVERSE
» String Functions: LENGTH
» String Functions: INSTR
» String Functions: CONCAT
» String Functions: CHAR

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?php
 
$string = "A sample string with several words";
 
$words = explode(" ",$string);
 
for($i=0;$i<count($words);$i++){$query_string .= "LIKE '%".$words[$i]."%' OR ";}
 
$query_string = substr($query_string,0,strlen($query_string)-4);
 
$sql = "SELECT * FROM test WHERE title ".$query_string." ORDER BY id DESC";
 
?> 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 10