[ create a new paste ] login | about

Link: http://codepad.org/wpHHdmCy    [ raw code | output | fork ]

PHP, pasted on Jan 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?

$words = array( 'apple', 'orange' );
$whereClause = '';
foreach( $words as $word) {
   $whereClause .= ' content LIKE "%' . $word . '%" OR';
}

// Remove last OR
$whereClause = substr($whereClause, 0, -2);

$sql = 'SELECT FROM yourtable WHERE' . $whereClause;

echo $sql;

?>


Output:
1
SELECT FROM yourtable WHERE content LIKE "%apple%" OR content LIKE "%orange%" 


Create a new paste based on this one


Comments: