Basically im using html, php, Smarty.
When i loop my results to display database table rows it ignores the first row of my database table.
So if i have a table with 3 rows (product_id = 1, product_id = 2, product_id = 3), it displays only product_id '2' and '3'.
I want to be able to display the first row - (product_id = 1)
.PHP
<?php
$new = ['product_id','product_category','product_price','product_quantity','product_about','product_color'];
//Database connection
$db = mysqli_connect('xxx','xxx','xxx','xxx')
or die('Error connecting to MySQL server.');
//access Smarty template engine
require_once('Smarty-3.1.30/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'views';
$smarty->compile_dir = 'tmp';
//query product page
$query = "SELECT * FROM cs_shop";
mysqli_query($db, $query) or die('Error querying database.');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
//query an array of products
$rows = array();
//loop start
while ($row = mysqli_fetch_array($result)) {
$rows[] = array(
'product_id' => $row['product_id'],
'product_category' => $row['product_category'],
'product_price' => $row['product_price'],
'product_quantity' => $row['product_quantity'],
'product_about' => $row['product_about'],
'product_color' => $row['product_color']
);
}
//db collect data
$smarty->assign('row', $rows);
//template
$smarty->display('index.tpl');
mysqli_close($db);
?>
.TPL
<div class="test divider">
<ul>
{foreach from=$row item="item"}
<li>{$item['product_id']}</li>
{/foreach}
</ul>
</div>
Results
2
3
Now how to display the missing id.. im new to this so any tips or help of any kind is much appreciated. Thanks in advance.
Expected Result
1
2
3