I have a index.html file, and a populated SQLite3 database called newdb.db, with one table 'NUMBERS' and the fields 'ID', 'NAME' and 'AVG'. This database is stored locally in same folder as the html file.
I simply want to get data from this table and use it within a in my HTML file to use.
I have attempted a couple examples from online but none seem to work.
Fine with creating a PHP file or something if needed.
<?php
try {
$sqlite = new PDO("sqlite:newdb.db");
$sqlite->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die($e);
}
$sth = $sqlite->prepare('SELECT *
FROM NUMBERS');
$sth->execute();
$result = $sth->fetchAll();
?>
<table style="width:100%">
<tr>
<th>ID</th>
<th>NAME</th>
<th>AVG</th>
</tr>
<?php
foreach($result as $row)
print '<tr><td>'.$row['ID'].'</td><td>'.$row['NAME'].'</td><td>'.$row['AVG'].'</td></tr>';
?>
</table>
while you trying to get data from database with an .html file without Server Client side i meant PHP or etc that's are imposibble thing to do. But maybe you can do that with node.js.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.