0
有人能告诉我为什么在移动到下一个值之前,这会产生两个字段值两次?动态表格输出 - 每个字段在出现前会出现两次
$titles = array('invlineid','invoiceid','quantity','unitprice','itemdesc');
$headers = array('invlineid','invoiceid','quantity','unitprice','itemdesc');
$sql = "SELECT ";
foreach(array_combine($headers, $titles) as $header => $title)
{
$sql .= "$header as $title,";
}
$sql .= "linetotal as linetotal";
$sql .= " FROM invoicelineitem";
$sql .= " WHERE invoiceid = 1096";
try
{
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error getting invoice line items.---' . $e . '----' . $sql;
include $_SERVER['DOCUMENT_ROOT'] . '/mincludes/error.html.php';
exit();
}
if ($result !== false)
{
$html_table = '<table>';
$html_table .= '<thead><tr>';
foreach($titles as $title)
{
$html_table .= "<th> $title </th>";
}
$html_table .= '</tr> </thead>';
$html_table .= '<tbody id="dataTable">';
foreach($result->fetchAll(PDO::FETCH_ASSOC) as $row)
{
$html_table .= '<tr>' . "\n";
foreach($row as $col)
{
$html_table .= '<td>';
$html_table .= '<input type=text name=' . $title;
$html_table .= ' value=' . $col . '>';
$html_table .= '</td>' . "\n";
}
$html_table .= '</tr>' . "\n";
}
}
$html_table .= '</tbody> <tr> </table>';
当它到达单个记录的末尾时,它会在表格中开始一个新行,但同样会产生两次每个值。
谢谢你,我想我在找的是PDO :: FETCH_ASSOC – recker277687 2015-02-05 17:29:55
会使用使用fetchall(PDO :: FETCH_NUM)使它在数据加载后更容易使用JavaScript动态添加行?当我需要保存对数据的任何更改时,这是否也是更好的方法? – recker277687 2015-02-05 17:41:30
好的,所以有了上面的代码,谁能告诉我如何将数据更改保存到数据库?我知道我需要遍历行,但我无法弄清楚是我的$ _POST看起来像抓取值。 – recker277687 2015-02-05 21:45:08