I've a code whhich should search for all data LIKE something in a table and print each one but I doesn't work at all
$words = explode(" ", $question);
foreach( $words as $each ) {
$sql = "SELECT * FROM $table WHERE question LIKE '%each%'";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($result)) {
printf(nl2br("%s
"), $row['question']);
}
}
You have a typo in the query (missing $
in %each$
):
$sql = "SELECT * FROM $table WHERE question LIKE '%$each%'";