Is it possible to create Bootstrap row for every 3 cols in PHP using foreach
loop but also to separate PHP code from View part.
This is my code
<?php include('connect.php');
$object = "";
$checkTables = $con -> prepare("SELECT * FROM available");
$checkTables -> execute();
$tables = $checkTables->fetchALL(PDO::FETCH_ASSOC);
$i = 0;
foreach($tables as $table):
if($table['avail'] == 0) {
$object .= '<div class="col-sm-4"><div class="table full"><p> 0 seats are avaiable.</p></div></div>';
} else {
$object .= '<div class="col-sm-4"><div id="table_'. $table['id'] .'" class="table"><p>' . $table['avail'] . ' seats are avaiable.</p></div></div>';
}
$i++;
endforeach;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container-fluid text-center">
<?php echo $object; ?>
</div><!-- End of container -->
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
I would like to keep foreach
loop at top of my file like this and separate html and php.