删除对象后,必须手动刷新页面才能在屏幕上进行更新


After i delete the object, the page has to be refreshed manually for the update to take place on the screen?

这是我的代码:

for($i = 0; $i < $printcoll->getlineCount(); $i++){
    $li   = $printcoll->getLineItem($i);
    $item = $li->getItem();
    if($item instanceof Product){
        print "Bike ID - ";
    }
    print $item->getId();

    if($item instanceof Product){
        print "&nbsp Price &pound";
    }
    print $item->getPrice();
    if($item instanceof Product){
        print "&nbsp Quantity - ";
    }
    print $li->getQuantity();


    print "<a href='myOO.php?delete=" . $i . "'>Delete</a>";
    echo "</br>";
}
if(isset($_GET['delete'])){
    $id = $_GET['delete'];
    $li = $printcoll->getLineItem($id);
    $printcoll->delLineItem($li);
}

此代码删除用户指定的对象(通过单击 a href)。但是,单击删除后,页面不会返回到"myOO.php"。它保留为"myOO.php?delete=".$i.,所以我必须手动删除地址栏中的"?delete=".$i.位,更新才能出现在页面上。有什么想法吗?

一种解决方案是将 ob_start(); 放在页面的开头,然后将 header('location:myOO.php') 放在 if 语句中。但是,我不确定这是执行此操作的正确方法。有什么想法吗?谢谢

问 Kennypu 已经指出,PHP 代码是在 Web 服务器上执行的。

这意味着每次在服务器上更改文档时,都必须手动或自动(例如通过使用AJAX)在客户端上重新加载页面,以便在服务器上重新执行PHP代码。