你可以使用echo语句在php中嵌入html。
<?php
$sqlacq ="SELECT * FROM tblAcq";
$resultacq = $conn->query($sqlacq);
?>
<table id="acq-tbl" class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header" width="10%">AcqID</th>
<th class="table-header">Data (an-luna-zi)</th>
<th class="table-header">AcqNumber</th>
<th class="table-header">AcqSupplier</th>
<th class="table-header">AcqNote</th>
<th class="table-header">InStocLa</th>
</tr>
</thead>
<tbody>
<?php
if ($resultacq->num_rows > 0) {
while($rowacq = $resultacq->fetch_assoc()) {
echo '<tr class="table-row" ondblclick="mySelection(event)">';
echo '<td>'.$rowacq["AcqID"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqDate\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqDate"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqNumber\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqNumber"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqSupplier\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqSupplier"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqNote\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqNote"].'</td>';
echo '<td>'.$rowacq["InStocLa"].'</td>';
echo '<td align="center"><a href="javascript:delete_id('.$rowacq["AcqID"].')"><img src="b_drop.png" alt="Delete" /></a></td>'
echo "</tr>";
}
}
?>
编辑:
在你的情况,$rowacq
是ASSOC阵列。所以你的最终代码将是,
<?php
$sqlacq ="SELECT * FROM tblAcq";
$resultacq = $conn->query($sqlacq);
?>
<table id="acq-tbl" class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header" width="10%">AcqID</th>
<th class="table-header">Data (an-luna-zi)</th>
<th class="table-header">AcqNumber</th>
<th class="table-header">AcqSupplier</th>
<th class="table-header">AcqNote</th>
<th class="table-header">InStocLa</th>
</tr>
</thead>
<tbody>
<?php
function table_print($rowacq) {
echo '<tr class="table-row" ondblclick="mySelection(event)">';
echo '<td>'.$rowacq["AcqID"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqDate\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqDate"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqNumber\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqNumber"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqSupplier\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqSupplier"].'</td>';
echo '<td contenteditable="true" onBlur="saveToDatabase(this,\'AcqNote\',\''.$rowacq["AcqID"].'\')" onClick="showEdit(this);">'.$rowacq["AcqNote"].'</td>';
echo '<td>'.$rowacq["InStocLa"].'</td>';
echo '<td align="center"><a href="javascript:delete_id('.$rowacq["AcqID"].')"><img src="b_drop.png" alt="Delete" /></a></td>'
echo "</tr>";
}
if ($resultacq->num_rows > 0) {
while($rowacq = $resultacq->fetch_assoc()) {
table_print($rowacq);
}
}
?>
onblur中'saveToDatabase()'函数的内容是什么?这是否也必须根据页面进行调整? – Thaillie
保留一个公共页面并添加一个函数以从表格中检索数据,将表格名称传递给函数 –
@Thaillie'saveToDatabase()'函数使用javascript和单独的php文件进行数据库行的内联更新。我认为只需要指向一个不同的php文件来更改已更新的表格 –