Codeigniter:为每个回声添加标签
Codeigniter: adding label to foreach echo
这是我的查看代码:
<?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;
}
?>
输出是
但是我希望输出像 Book ID:1、Book Name:qweqweqweqweqwe、价格 123.00 等等,以 table 的形式我能做到吗?
使用 php 函数连接您的字符串。
echo "Book ID:".$books->book_id.", Book Name: ".$books->book_name;
像这样。
这样使用:
echo "Book ID : $books->book_id";
双引号会自动识别变量并执行。
你也可以试试:-
echo 'Book ID:'. $books->book_id;
请选择您容易阅读的一项。
希望对您有所帮助..
<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>
这是我的查看代码:
<?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;
}
?>
输出是
但是我希望输出像 Book ID:1、Book Name:qweqweqweqweqwe、价格 123.00 等等,以 table 的形式我能做到吗?
使用 php 函数连接您的字符串。
echo "Book ID:".$books->book_id.", Book Name: ".$books->book_name;
像这样。
这样使用:
echo "Book ID : $books->book_id";
双引号会自动识别变量并执行。
你也可以试试:-
echo 'Book ID:'. $books->book_id;
请选择您容易阅读的一项。
希望对您有所帮助..
<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>