$sql = q("INSERT INTO book SET id_book = '', date_add = '".es(date('Ymd H:i:s'))."', title_book = '".es($_POST['title_book'])."', annot_book = '".es($_POST['annot_book'])."', descr_book = '".es($_POST['descr_book'])."'"); $id_book= DB::_()->insert_id; $a_f_author = array(); foreach($_POST['FIO_author'] as $key=>$value){ $f = array(0=>'NULL',1=>'"'.$value.'"',2=>'"'.$_POST['alias'][$key].'"'); $a_f_author[] = '(' . implode(',', $f) . ')';} $sql2 = "INSERT INTO author_book (id_author,FIO,alias) VALUES" .implode(',', $a_f_author); echo wtf($sql2); //Результат без запроса,просто вывод на экран: INSERT INTO author_book (id_author,FIO,alias) VALUES(NULL,"Ибрагимов","Ибра"),(NULL,"Файзуллин","Фейз") 

Book - Linking Table - Author.

  1. Added author to table Author
  2. Added a book to the table Book.

But I can not understand how to add the id of two authors to the Spreadsheet? ..

  • and what data comes to POST - how do authors define correspondence to books? - Ale_x

1 answer 1

The one-to-many, many-to-one bundle is poorly suited for this task. I would recommend that you use many-to-many books to link books. Those. three tables (authors, books and a table of links (book_id, author_id)). Thus one book may have several authors, and one author may have several books.