Tell me. I have a base of books. Each book has a publisher, it is repeated in the database. How can I display a table for publishers. Format:

Издательство 1 -Книга 1 -Книга 2 Издательство 2 -Книга 1 -Книга 2 

I have a request of this type

  $todb = $mysqli->query('SELECT * FROM book LEFT JOIN bookextend ON book.id = bookextend .book_id ORDER BY ID DESC'); 

As I understand it, I need to do two while

  • it would be nice to attach the structure of both tables - Alex

1 answer 1

I figured it out myself with the answer. Made two cycles.

  $todb = $mysqli->query(' SELECT DISTINCT izdat FROM bookextend ORDER BY izdat DESC '); while ($row = $todb->fetch_array()) { echo $row['izdat'].'<br>'; $todb2 = $mysqli->query('SELECT * FROM book LEFT JOIN bookextend ON book.id = bookextend .book_id ORDER BY ID DESC'); while ($row2 = $todb2->fetch_array()) { echo $row2['book']; } } 
  • do not do it this way. drag all data in one request as it was. When you get an array of knowledge, go over it, and group items with the same publishers. Then use a double cycle for output. Sort the sample by publisher and then title. And during processing, check the change of the publisher at an iteration with respect to the previous value. In principle, there are a lot of questions about grouping. - teran