这是我的观看代码:
<?php
foreach($books as $books) {
echo $books->book_id;
echo $books->book_name;
echo $books->description;
echo $books->author;
echo $books->publisher;
echo $books->pages;
echo $books->publication_date;
echo $books->price;
echo $books->status;
echo $books->quantity;
echo $books->genres;
echo $books->user_rating;
echo $books->reviews;
}
?>
输出为
但是我希望输出类似于书籍ID:1,书名:qweqweqweqweqwe,价格123.00等等,以表格形式我能够做到吗?
答案 0 :(得分:0)
用php函数连接你的字符串。
echo "Book ID:".$books->book_id.", Book Name: ".$books->book_name;
就像这样。
答案 1 :(得分:0)
像这样使用:
echo "Book ID : $books->book_id";
双引号将自动识别变量并执行它们。
您也可以尝试: -
echo 'Book ID:'. $books->book_id;
请选择哪一个易于阅读。
答案 2 :(得分:0)
我希望这会对你有帮助..
<table>
<th>
<td>Book Id</td>
<td>Book Name</td>
<td>Description</td>
<td>Author</td>
<td>Publisher</td>
<td>Pages</td>
<td>Publication Date</td>
<td>Price</td>
<td>status</td>
<td>Quantity</td>
<td>Genres</td>
<td>User Rating</td>
<td>Reviews</td>
</th>
<?php foreach($books as $book) { ?>
<tr>
<td><?php echo $book->book_id ?></td>
<td><?php echo $book->book_name ?></td>
<td><?php echo $book->description ?></td>
<td><?php echo $book->author ?></td>
<td><?php echo $book->publisher ?></td>
<td><?php echo $book->pages ?></td>
<td><?php echo $book->publication_date ?></td>
<td><?php echo $book->price ?></td>
<td><?php echo $book->status ?></td>
<td><?php echo $book->quantity ?></td>
<td><?php echo $book->genres ?></td>
<td><?php echo $book->user_rating ?></td>
<td><?php echo $book->reviews ?></td>
</tr>
<?php } ?>
</table>