如果可以在更新数据库中的表后再次运行php行吗?
我有一个触发jQuery.post的html按钮:
btn.onclick = function(e) {
$.post('inc/pstPts.php',
{
pts: pts
});
}
在pstPts.php中,我进行查询,并成功更新目标行。 我用html加载了那行:
<?php
for ($i=0; $i < $q->query_numrows(); $i++) {
print '<tr><td>' . $d[$i]['user_nom'] . ' ';
print '<tr><td>' . $d[$i]['user_ape'] . ' ';
print '<tr><td>' . $d[$i]['user_email'] . ' ';
print '<tr><td>' . $d[$i]['user_cel'] . ' '; }
?>
但这已经加载了旧数据。
我希望在更新后只运行这5行。
答案 0 :(得分:0)
由于您的代码非常少,我将发布伪代码以提供一个想法。
服务器SIde:
//get the inputs from $_POST
// update the database
$update = $db->update($_POST); //simplified. just an example
if($update !== false)
{
$entry = $db->query("SELECT * FROM foo ...... WHERE id = $_POST['id']"); //take care of sql injections.
foreach($entry as $i)
{
//build up the html and echo it
}
}
注意:绑定params(为了使查询免于sql注入),请按照此binding links
中的示例进行操作客户端:
$.post({
//url
}).done(function(data){
$('#selector').html(data);
});
...完成