1 回答
TA贡献1816条经验 获得超4个赞
在文件中,page1.php您将执行以下操作:
$result = Db::query($query); // the query should return column ID for each row
$text = "<table class='table table-bordered table-sm'><thead>$table_header</thead><tbody>";
if (!pg_num_rows($result))
{
$no_results = "Nothing was found !";
}
else
{
$no_results = "Results found: ".pg_num_rows($result);
}
while($row = pg_fetch_row($result))
{
// the popup will open `page2.php?id=ID-of-the-row`
$text .= "<tr><td><button class='btn btn-primary' type='button' id='buttonCreate' onclick='showPopup(\"update.php?id=".$row['id']."\")'>EDIT</button></td>";
foreach ($row as $value)
{
$text .= "<td style='word-break: keep-all;'>".htmlspecialchars($value)."</td>";
}
$text .= "</tr>";
}
$text .= "</tbody></table>";
$response = new Response();
$response->assign('no_results', 'innerHTML', $no_results);
$response->assign('table_body', 'innerHTML', $text);
return $response;
然后,在文件中,page2.php您将执行以下操作:
$result = Db::query($query); // the query will use $_GET['id'] in order to fetch the specific row
$text = "<table class='table table-bordered table-sm'><thead>$table_header</thead><tbody>";
if (!pg_num_rows($result))
{
$no_results = "Nothing was found !";
}
else
{
$no_results = "Results found: ".pg_num_rows($result);
}
// there should be no more than 1 row
while($row = pg_fetch_assoc($result))
{
$text .= "<tr>";
foreach ($row as $key => $value)
{
$text .= "<td style='word-break: keep-all;'><input type=text name='".$key."' value='".htmlspecialchars($value)."'></td>";
}
$text .= "</tr>";
}
$text .= "</tbody></table>";
$response = new Response();
$response->assign('no_results', 'innerHTML', $no_results);
$response->assign('table_body', 'innerHTML', $text);
return $response;
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报