I am attempting to create a html table using php to retrieve data from an SQLite3 database. The database contains a table of users and bills with information in each row about each. I am trying to display the table but the page will not load and I cannot figure out what is wrong in my code. Any help would be appreciated, thanks!
My database schema:
CREATE TABLE users(id integer primary key, Username varchar(15), FirstName varchar(15), LastName varchar(15), Email varchar(50), HouseName varchar(20), Phone integer, salt varchar(50), Encrypted_password varchar(50));
CREATE TABLE bills(id integer primary key, HouseName varchar(20), Bill varchar(20), Amount real, PaidBy varchar(20), Date TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
html/php table:
<table>
<thead>
<tr>
<th width="100"> Bill</th>
<th width="100">Amount </th>
<th width="100">Paid By</th>
<th width="100">Added On</th>
<th width="100">You owe</th>
</tr>
</thead>
<tbody>
<?php
require ‘session.php’;
require ‘database.php’;
while(($row = $querybills->fetchArray())) {
$html .= "<tr><td>"$row['Bill']"</td><td>"$row['Amount']"</td><td>"$row['PaidBy']"</td><td>"$row['Date']"</td><td>"$row['Amount'] / $billscount"</td> </tr>";
}
echo $html;
?>
</tbody>
</table>
session.php:
<?php
session_start();
require 'database.php';
if(isset($_SESSION['id'])) {
$db = new Database();
$queryuser = "SELECT * FROM users WHERE(id = '".$_SESSION['id']."')";
$user = $db->querySingle($queryuser);
$querybills = $db->query("SELECT * FROM bills WHERE(HouseName == ".$user['HouseName'].")");
$bill = $db->querySingle($querybills);
$billscount = $db->query("SELECT COUNT(*) FROM users WHERE(HouseName == ".$user['HouseName'].")");
} else {
header('Location:login.php');
}
?>
database.php:
<?php
class Database {
private $database;
function __construct() {
$this->database = $this->getConnection();
}
function __destruct() {
$this->database->close();
}
function exec($query) {
$this->database->exec($query);
}
function query($query) {
$result = $this->database->query($query);
return $result;
}
function querySingle($query) {
$result = $this->database->querySingle($query,true);
return $result;
}
function prepare($query) {
return $this->database->prepare($query);
}
function escapeString($string) {
return $this->database->escapeString($string);
}
private function getConnection() {
$conn = new SQLite3('bills.db');
return $conn;
}
}
?>
Aucun commentaire:
Enregistrer un commentaire