検索機能 (Google Books API を介して本を検索する) があり、foreach ループを使用して 10 件の結果がテーブル形式で返されます。ユーザーが選択した 10 のどれに応じて、実際の検索結果を渡す方法を見つけるために数日間試みてきました。私は多くの答えを見つけましたが、私の特定の要件に合うものはないようです。結果ごとに変数を動的に作成する必要があると思いますが、おそらく間違った方向に進んでいますか? データのテーブルを選択するためにテーブル ID を動的に作成する必要があるかもしれませんが、その方法がわかりません。または、入力選択行の id 値を動的に変更しますか?
<strong><p style="font-size: 16px; text-align: center";>Top 10 Results for "<?php echo @$_POST['q']; ?>"</p></strong>
<strong><p style="font-size: 14px; text-align: center";>choose a book to select as your topic</p></strong>
<table style="width:400px">
<col width="325">
<col width="75">
<?php $i=0; foreach ($data['items'] as $item) { $i++;
$b_title[$i] = $i; ?>
<tr>
<td>
<strong><u><div style="font-size: 14px";><?php printf($item['volumeInfo']['title']);
$b_title[$i] = $item['volumeInfo']['title']?></u></div></strong>
<strong>Author: </strong><?php printf( $item['volumeInfo']['authors'][0]);?><br />
<strong>Published: </strong><?php printf( $item['volumeInfo']['publishedDate']); ?><br />
<strong>Page(s): </strong><?php printf( $item['volumeInfo']['pageCount']); ?><br />
<strong>Publisher: </strong><?php printf( $item['volumeInfo']['publisher']); ?><br />
<strong>Category: </strong><?php printf( strtolower($item['volumeInfo']['printType']).', '.strtolower($item['volumeInfo']['categories'][0])); ?>
<strong>ISBN: </strong><?php printf( $item['volumeInfo']['industryIdentifiers'][0]['identifier']); ?></td>
<td><p><input type="submit" method="post" name="selectbook" value="Select" class="btn" id="book'.$i.'" /></p>
<input type="hidden" name="value[]" value="<?=$i?>" />
<img src="<?php printf( rawurldecode($item['volumeInfo']['imageLinks']['smallThumbnail'])); ?>" />
</td>
<tr><td style="width:420px"><p><strong>Description: </strong><?php printf( $item['volumeInfo']['description']); ?><br /></p></td>
<?php
//assigning values in order to pass to javascript variables - client to server
if ( isset( $_POST['submit'] )) {
$book_title = $b_title[$i];
$book_cover = $book_cover_i;
}
$book_cover = $item['volumeInfo']['imageLinks']['smallThumbnail'];
$book_author = $item['volumeInfo']['authors'][0];
$book_published = $item['volumeInfo']['publishedDate'];
$book_description = $item['volumeInfo']['description'];
$book_pages = $item['volumeInfo']['pageCount'];
$book_publisher = $item['volumeInfo']['publisher'];
$book_ISBN = $item['volumeInfo']['industryIdentifiers'][0]['identifier'];
?>