CREATE TABLE IF NOT EXISTS `products` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(200) NOT NULL, `price` int(11) NOT NULL, `qty` int(11) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
<?php /* Database config */ $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_database = 'tutorial'; /* End config */ $db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ?>
<table id="resultTable" data-responsive="table" style="text-align: left; width: 400px;" border="1" cellspacing="0" cellpadding="4"> <thead> <tr> <th> Name </th> <th> Price </th> <th> Quantity </th> </tr> </thead> <tbody> <?php include('connect.php'); $result = $db->prepare("SELECT * FROM products"); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ $availableqty=$row['qty']; if ($availableqty < 10) { echo '<tr class="record" bgcolor="red" style="color: white;">'; } else { echo '<tr class="record">'; } ?> <td><?php echo $row['name']; ?></td> <td><?php echo $row['price']; ?></td> <td><?php echo $row['qty']; ?></td> </tr> <?php } ?> </tbody> </table>
$availableqty=$row['qty']; if ($availableqty < 10) { echo '<tr class="record" bgcolor="red" style="color: white;">'; } else { echo '<tr class="record">'; }