0

For example the value of array is:

Array ( [0] => what [1] => is [2] => life [3] => )  

This value is stored in a variable called $specialized

$string = "SELECT * FROM questions where";        
$intA = 0;
foreach ($specailized as $spec) {
    $string += " question like '%" + $spec +"'% ";  
    if ($intA > 1) { 
        $str += " and ";
    }
    $intA++;
}
print($string);

The result is always numbers. Like 001 if this possible? I want to get a string value stored in $string like this.

SELECT * FROM questions where question like '% what%' and question like '% is%' and question like '%life%' 
Hafez Divandari
  • 8,381
  • 4
  • 46
  • 63
codezzz
  • 27
  • 6

1 Answers1

1

I think you need this

$string = "SELECT * FROM questions where 1=1 ";        
$specailized = array("what","is","life");
foreach ($specailized as $spec) {
    $string .= " and question like '%" . $spec ."%' ";  
}

echo $string;

Also note, that if array values comes from user, then you should care about sql injections

Oto Shavadze
  • 40,603
  • 55
  • 152
  • 236