The code problem:
<?php
if(strtolower($item["category"]) == "books" ) {
?>
<tr>
<th>Category</th>
<td><?php echo $item["category"] ?></td>
</tr>
<?php } ?>
Why I have to write it like that? Instead of:
<?php
if() {
Do some things!
}
?>
You can write PHP in HTML but you cant write HTML IN PHP(without using echo).
AFTER THIS
<?php
if(strtolower($item["category"]) == "books" ) {
?>
You close the php tag to add html.
Then you open the php tag to put the closing braces for if and then close it back so that you can add html
This is just basic stuff, but short explanation is that when server is processing your *.php file and sending it to the browser it starts parsing your file when he sees <?php
tag and stops parsing when he runs into ?>
tag or the end of the file. So, anything in between those two will be seen by the server as a PHP code and the rest will be sent directly to browser.
Your code above can be written in several different ways to do the same thing, all depends on what you want to do. This is also valid in PHP and sometimes it's much more readable
<?php if (strtolower($item["category"]) == "books"): ?>
<tr>
<th>Category</th>
<td><?php echo $item["category"] ?></td>
</tr>
<?php endif; ?>