I have an array of words and I want to iterate over this array to check if any of these words exist in my sql table. If they exist, it should return the particular row.
I have tried using a sql statement inside a for loop that iterates over a variable i to and checks if each word in the array is present in the SQL table.
/*This code produces the separate tags or words from the 'tag' which contains comma separated values*/
if($result == True){
while($row = $result->fetch_assoc()){
$tag_string = $row['tag'];
echo $row['tag'];
}
}
$tag_arr = explode(",", $tag_string);
/*This is the part where there is an error (Undefined index i in the sql query)*/
for($i=0; $i <= count($tag_arr); $i++){
$sql1 = "select count from skills where skills.skill like '%'$tag_arr[i]'%' or '%'tag_arr[i] or tag_arr[i]'%'";
$result1 = mysqli_query($conn, $sql1);
if($result1 == True){
while($row = $result1->fetch_assoc()){
//$tag_string = $row['tag'];
echo $row['count'];
}
}
}
There was an error in the SQL query statement.
'Undefined index: i'
This is the structure of my 'skills' table: