This code is supposted Show all of the Table Reg_Log. The code can show but... if the table is empty, the code show a message saying "You have no purchases.".
but someting is wrong...
$Check_Reg = $_SESSION['user']['username'];
if(!empty($Check_Reg))
{
$dbh = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
$search = $dbh->prepare("SELECT ID_Article, Data_Compra, Price, Cred_Depois FROM reg_log ORDER BY Data_Compra DESC");
$search->execute();
$checkUser = $search->fetchAll();
foreach($checkUser as $u)
{
echo "<table>";
echo "<tr>";
echo "<th><b>Article ID</b></th>";
echo "<th><b>Price</b></th>";
echo "<th><b>Savings</b></th>";
echo "<th><b>Data & Hora</b></th>";
echo "</tr>";
echo "<br /><tr><td>" . $u['ID_Article'] . "</td><td>". $u['Price'] . "</td><td>" . $u['Cred_Depois'] . "</td><td>" . $u['Data_Compra'] . "</td></tr> " ;
echo "</table>";
$dbh = null; //close db
}
} else {
$emptyField = False;
echo "You have no purchases.";
}