大家好,我正在使用select命令从数据库查看pdf,它正在运行,但是每次刷新页面时,它都会尝试下载所有pdf。我希望它是正常列表,然后单击一下即可下载。
这是我的代码
<?php
function selectFishprice()
{
try {
$connection = connect();
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT price AS pdf_path, Date FROM upload WHERE id = 1";
$statement = $connection->query($sqlQuery);
$statement->setFetchMode(PDO::FETCH_ASSOC);
$Fishprices = $statement->fetchAll();
if (!empty($Fishprices)) {
return $Fishprices;
} else {
return NULL;
}
} catch (PDOException $exception) {
die("Error: " . $exception->getMessage());
}
}
$fishPrices = selectFishprice();
?>
<table id="users">
<thead>
<tr>
<th scope="col">Fish Market Price</th>
<th scope="col">As of</th>
</tr>
</thead>
<tbody>
<?php
if (!empty($fishPrices)) {
foreach ($fishPrices as $fishPrice) {
$date = strtotime($fishPrice['Date']);
?>
<tr class="table-primary">
<td scope="row"><img src="<?= $fishPrice['pdf_path'] ?>"/></td>
<td scope="row"><?= date('M j Y', $date)?></td>
<?php
}
} else {
?>
<tr class="table-primary">
<td class="text-center" colspan="4" scope="row">No records found.</td>
</tr>
<?php
}
?>
</tbody>
</table>
我从网站上读取了使用“标头”的信息,但是我不知道该将“标头”放在哪里?感谢您的任何帮助,谢谢
答案 0 :(得分:0)
function selectFishprice()
{
try {
$connection = connect();
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$statement = $connection->query("SELECT price, Date FROM upload WHERE id = 1 ");
$statement->setFetchMode(PDO::FETCH_ASSOC);
$Fishprices = $statement->fetchAll();
if (!empty($Fishprices)) {
return $Fishprices;
} else {
return NULL;
}
} catch (PDOException $exception) {
die("Error: " . $exception->getMessage());
}
}
$fishPrices = selectFishprice();
<table id="users">
<thead>
<tr>
<th scope="col">Fish Market Price</th>
<th scope="col">As of</th>
</thead>
<tbody>
<?php
if(!empty($fishPrices)) {
foreach ($fishPrices as $fishPrice) {
$date = strtotime($fishPrice['Date']);
?>
<tr class="table-primary">
<td scope="row"><a href ="<?= $fishPrice['price'] ?>" target="_blank"><img src="" alt="PDF"/></a></td>
<td scope="row"><?= date('M j Y', $date)?></td>
<?php
}
} else {
?>
<tr class="table-primary">
<td class="text-center" colspan="4" scope="row">No records found.</td>
</tr>
<?php
}
?>
</tbody>
</table>