(Yes, the title should have been more understandable but honestly I didn't know how to set it.)
What I am trying to do is creating a online dictionary of Latin. When you search a word the code (I am using some index so don't worry about selectivity) will search that name row by row inside a string (the string becomes an array using explode).
I've created a table called 'test' just to practice with this code but it works in the same way of the one of the dictionary: here the table
Before trying to load data from database I've checked if it worked locally. It works locally. Here the code:
$word_searched = 'puellam';
$string_declination = ('puella,puellae,puellae,puellam,puella,puella');
$array_declination = explode(",", $string_declination);
$check = 0;
foreach ($array_declinazion as $item) {
if ( (strcmp($item, $word_searched)) === 0 ){
$check++;
}
}
if ( $check > 0) {
echo 'yes';
}
Then I've tryed to load the data from the database (the table 'test') using the same code. Here the code:
$query = "SELECT * FROM test";
$result = mysqli_query($conn, $query) or die('Error running query!');
$check = 0;
$string = 'puellam';
while($row = $result->fetch_assoc()) {
$array_declinazione = explode(",", $row['declinazione']);
foreach ($array_declinazione as $item) {
if ( (strcmp($item, $string)) === 0 ){
$check++;
}
}
}
if ( $check > 0) {
echo 'yes';
}
The first code works perfectly but the second one doesn't even though it's the same way. I just don't understand why.