单击按钮后,我正在导出完整的表格信息,它的工作正常。...
现在我在每行中添加了按钮,现在我单击了第一行中的按钮后,我只想导出pdf中的第一行详细信息。我在这里做错了吗?
<?php
$result = mysqli_query($con,"SELECT * FROM orders");
echo "<table border='1'>
<tr>
<th>order</th>
<th>payment</th>
<th>download</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
echo "<tr>";
echo "<td>" . $row['order_id'] . "</td>";
echo "<td>" . $row['payment_type'] . "</td>";
echo "<td><button><a href ='index.php?id=<?php echo $row['id']?>'>Download</a></button></td>";
echo "</tr>";
}
echo "</table>";
?>
更新
我遇到如下语法错误,但是我检查了所有与语法错误有关的内容,无法找到行中语法错误的位置:
echo "<td><button><a href ='index.php?id=<?php echo $row['id']?>'>Download</a></button></td>";
PHP语法检查:解析错误:语法错误,意外的'' (T_ENCAPSED_AND_WHITESPACE),期望为“-”或标识符(T_STRING)或 变量(T_VARIABLE)或数字(T_NUM_STRING)
答案 0 :(得分:3)
您在回显函数中使用<?php ?>
标签,这将无法工作。
echo "<td><button><a href ='index.php?id=<?php echo $row['id']?>'>Download</a></button></td>";
将其更改为此:
echo "<td><button><a href='index.php?id=" . $row['id'] . "'>Download</a></button></td>";
答案 1 :(得分:2)
这是因为要将PHP标记放入echo语句中。您已经在PHP环境中,无需再打开另一个。仅在将原始HTML直接硬编码到输出中并且想要在其中添加PHP片段时,才使用这些标记。这是相反的情况。
更改
echo "<td><button><a href ='index.php?id=<?php echo $row['id']?>'>Download</a></button></td>";
到
echo "<td><button><a href ='index.php?id=$row['id']'>Download</a></button></td>";
或
echo "<td><button><a href ='index.php?id=".$row['id']."'>Download</a></button></td>";
答案 2 :(得分:1)
include('database.php');
$database = new Database();
$result = $database->runQuery("SELECT order_id, payment_type FROM orders where id = '".$_REQUEST['id']."'");
$header = $database->runQuery("SELECT UCASE(`COLUMN_NAME`)
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='do_management4'
AND `TABLE_NAME`='orders'
and `COLUMN_NAME` in ('order_id','payment_type')");
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
foreach($header as $heading) {
foreach($heading as $column_heading)
$pdf->Cell(95,12,$column_heading,1);
}
if($result)
$row = $result[0]; //here you can get the result and change according to row variable either in array or std object
//foreach($result as $row) {
$pdf->Ln();
foreach($row as $column)
$pdf->Cell(95,12,$column,1);
//}
$pdf->Output();