php - Show values of the db in organization with Bootstrap row class for every 3 columns
350
I wrote some code which retrieves data from the database and gives the output to the web page using php. I use bootstrap to show the data in some organized way on the web page. But the code returns some syntax errors.
function break_array($array, $page_size) {
$arrays = array();
$i = 0;
foreach ($array as $index => $item) {
if ($i++ % $page_size == 0) {
$arrays[] = array();
$current = & $arrays[count($arrays)-1];
}
$current[] = $item;
}
return $arrays;
}
?>
<?php
foreach (break_array($row = $sql->fetch(), 3) as $columns) {
<div > *** Error is gives on here ***
foreach ($columns as $article) {
<div >
<p>{{ strip_tags(str_limit($article->body, $limit = 90, $end = '...')) }}</p>
</div>
}
</div>
}
How can I correct this?
Answer
Solution:
Your 'code' is mixing HTML with PHP in an incorrect way. PHP needs to be interpreted server side to generate HTML, this HTML is then sent to the browser and is the source-code for the browser.
You can mix PHP & HTML in a couple of ways. Here some examples:
1. Enter and leaver php parsing mode
Note that all PHP-code that needs to be interpreted is between
<?php ... ?>
tags, this is interpreted at the server side.2. Echo HTML as strings in PHP
Note that all HTML-code is inside a php
echo()
statement: