如果可以在更新数据库中的表后再次运行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行。
由于您的代码非常少,我将发布伪代码来给出一个想法。
服务器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注入的影响),请遵循绑定链接中的示例
客户端:
$.post({
//url
}).done(function(data){
$('#selector').html(data);
});
完成。。。。