<?php
$mysqli=new Mysqli('localhost','root','548280','Misha');
$mysqli->query("SET NAMES 'UTF8'");
$g=$mysqli->query("SELECT authors.f_name, authors.s_name,books.b_name FROM authors
JOIN author_books ON authors.id=author_books.author_id JOIN
books ON books.id=author_books.book_id WHERE authors.f_name='Дмитрий' OR authors.s_name LIKE 'А%' GROUP BY authors.f_name,authors.s_name");
$result=[];
while($b=mysqli_fetch_assoc($g)){
$result[]=$b;
}
?>
<h4>Книги, имя авторов которых Дмитрий или фамилия на А</h4>
<table border="1">
<tr>
<th>Книгa</th>
<th>Автор</th>
</tr>
<?php
foreach($result as $v){
echo '<tr>
<td>'.$v['b_name'].'</td>
<td>'.$v['f_name'].' '.$v['s_name'].'</td>
</tr> ';
}
?>
$g=$mysqli->query("SELECT authors.f_name, authors.s_name,books.b_name FROM authors
JOIN author_books ON authors.id=author_books.author_id JOIN
books ON books.id=author_books.book_id WHERE authors.f_name='Дмитрий' OR authors.s_name LIKE 'А%' GROUP BY authors.f_name,authors.s_name");
$g=$mysqli->query("SELECT CONCAT(authors.f_name,' ',authors.s_name) as name, books.b_name FROM authors
JOIN author_books ON authors.id=author_books.author_id JOIN
books ON books.id=author_books.book_id WHERE authors.f_name='Дмитрий' OR authors.s_name LIKE 'А%' GROUP BY name");
foreach($result as $v){
echo '<tr>
<td>'.$v['b_name'].'</td>
<td>'.$v["name"].'</td>
</tr> ';
}