Как получить доступ к значениям SQL в предложении Group с помощью подготовленного оператора Mysqli

Я пытаюсь запустить подготовленное заявление, используя mysqli.

$stmt = mysqli_stmt_init($connection);
mysqli_stmt_prepare($stmt, "SELECT books.book_id, title, publish_date, thumbnail,
GROUP_CONCAT(CONCAT(authors.author_id,' ', first_name,' ', last_name))
FROM books, authors, books_authors
WHERE books.book_id = books_authors.book_id
AND authors.author_id = books_authors.author_id
GROUP BY books.book_id, title, publish_date, thumbnail");

mysqli_stmt_execute($stmt);

mysqli_stmt_bind_result($stmt, books.book_id, title, publish_date, thumbnail, $author_id);

Все значения отображаются правильно, кроме имен авторов. Имена авторов не отображаются вообще. Поля first_name и last_name находятся в GROUP BY пункт в SQL, Как мне получить доступ к этим значениям в mysqli_stmt_bind_result без получения ошибки числа mysqli_stmt_bind_result поля не соответствующие mysqli_stmt_prepare?

Я получаю результаты в цикле

while (mysqli_stmt_fetch($stmt))

-1

Решение

Попробуйте это может помочь вам

$stmt = mysqli_stmt_init($connection);
mysqli_stmt_prepare($stmt, "SELECT books.book_id, title, publish_date, thumbnail,
GROUP_CONCAT(CONCAT(authors.author_id,' ', first_name,' ', last_name))
FROM books, authors, books_authors
WHERE books.book_id = books_authors.book_id
AND authors.author_id = books_authors.author_id
GROUP BY books.book_id, title, publish_date, thumbnail");

mysqli_stmt_execute($stmt);

mysqli_stmt_bind_result($stmt, books.book_id, title, publish_date, thumbnail, $author_id);
while (mysqli_stmt_fetch($stmt)) {
printf("%s %s\n", $col1, $col2);
}
-1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector