Having looked more closely at your code, I see a few things wrong now. Mainly how you are trying to access array data.
It is a multi dimensional array, with rows each containing a sub-array. As you have seen, much of the data is duplicated and redundant. This is why I advise only to use the first row [0]
to get the film data (which is duplicated in every row), then only use a loop to access the cast list from each row.
Assuming the data from the DB looks something like this:-
$filmData = [
[
'titolo' => 'Good Will Hunting',
'imagelink' => 'img.jpg',
'data' => '1997',
'regia_nome' => 'Gus',
'regia' => 'Van Sant',
'contenuti' => 'Contents...',
'nome' => 'Matt',
'cognome' => 'Damon',
'role' => 'Will Hunting (ragazzo geniale)'
],
[
'titolo' => 'Good Will Hunting',
'imagelink' => 'img.jpg',
'data' => '1997',
'regia_nome' => 'Gus',
'regia' => 'Van Sant',
'contenuti' => 'Contents...',
'nome' => 'Robin',
'cognome' => 'Williams',
'role' => 'Sean Maguire (psicologo)'
]
];
I had to make this to test the code, not having your database.
When accessing data from the first row of a multi dimensional array, you will first specify the row, then the data column: $array[0]['column']
Also take not of your quote marks, you need quotes for the column name.
When echoing a string in double quotes, you may insert a variable name without breaking out of the quotes, but when accessing a multi dimensional array like this, you will need to break out of the quotes, which can get messy.
$result = mysqli_query($db, $query);
$filmData = mysqli_fetch_array($result);
echo "<h2>".$filmData[0]['titolo']; // Get the title from the first row
if($filmData[0]['imagelink'] != ''){echo '<img src="'.$filmData[0]['imagelink'].'" height="200px" class="fr">';}
echo "</h2>";
echo "<p>data:<b>".$filmData[0]['data']."</b> - regista: ".$filmData[0]['regia_nome']." <a href='hashtag-registi.php?tag=".$filmData[0]['regia']."'>".$filmData[0]['regia']."</a></p>";
echo "<blockquote><p>".$filmData[0]['contenuti']."</p></blockquote>"; // All this comes from the first row
echo "<p class='actors'>";
foreach($filmData as $cast) { // Now take the cast data in a loop...
echo "<span><a href=\"hashtag-actors.php?tag=".$cast['cognome']."\">".$cast['nome']." ".$cast['cognome']."</a> (as ".$cast['role'].")</span>";
}