PHP/MySQL query. Table header should not loop. Please help?

retlav

New member
I have this PHP/MySQL query that works. but it loops the heading of the table for each result. I would like the table heading to appear only once. Can someone help


// books start
$get_books_sql = "SELECT * FROM books where course_id = '$course_id' AND year = $year";
$get_books = mysqli_query($mysqli, $get_books_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_books) > 0) {
$display_block_c .= "<br><br><b>Books</b><br>";
while ($books_info = mysqli_fetch_array($get_books)) {
$book_name = $books_info['book_name'];
$isbn = $books_info['isbn'];
$author = $books_info['author'];
$publisher = $books_info['publisher'];
$copyright_date = $books_info['copyright_date'];
$status = $books_info['status'];
$price = $books_info['price'];
$display_block_c .= "<table class='sample'>
<tr>
<td>Book</td>
<td>ISBN</td>
<td>Author</td>
<td>Publisher</td>
<td>Status</td>
<td>Price</td>
</tr>
<tr>
<td>$book_name ($copyright_date)</td>
<td>$isbn</td>
<td> $author</td>
<td>$publisher</td>
<td>$status</td>
<td>$price</td>
</tr>
</table>";
}

}
I am trying this... and i am getting an error... please assist...

$get_books_sql = "SELECT * FROM books where course_id = '$course_id' AND year = $year";
$get_books = mysqli_query($mysqli, $get_books_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_books) > 0) {
$display_block_c = "<br><br><b>Books</b><br>";
$display_block_c .= "<table class='sample'>";
while ($books_info = mysqli_fetch_array($get_books)) {
$book_name = $books_info['book_name'];
$isbn = $books_info['isbn'];
$author = $books_info['author'];
$publisher = $books_info['publisher'];
$copyright_date = $books_info['copyright_date'];
$status = $books_info['status'];
$price = $books_info['price'];
$display_block_c .= ' <tr>
<td>Book</td>
<td>ISBN</td>
<td>Author</td>
<td>Publisher</td>
<td>Status</td>
<td>Price</td>
</tr>
<tr>
<td>$book_name ($copyright_date)</td>
<td>$isbn</td>
<td> $author</td>
<td>$publisher</td>
<td>$status</t
 
Back
Top