如何在现有行中添加行?

时间:2015-08-21 05:50:30

标签: php jquery mysql ajax

我编写了分页代码。这很有效。但是我想这样做,当我点击第二页时,这个页面将显示在现有的第一页下,没有与整页相同的刷新页面。我的意思是在没有刷新页面的情况下将后页附加到新页面。

请大家试着理解我的问题。

查看\模板\ product_class.php

<?php
include "common/head.php";
class LoginTpl{
    function product(){
        $products = $this->products;
        //echo "<pre>"; print_r($products); exit;
?>  
<script>
    function ToggleAll(source) {
        var checkboxes = document.getElementsByName('checkbox[]');
        for(var i=0, n=checkboxes.length;i<n;i++) {
            checkboxes[i].checked = source.checked;
        }
    }
</script>
<body>
 <div class="jumbotron text-center">
    <h2>View Upload Product</h2>
</div>
    <div class="col-sm-12 menu">
        <div class="row">
            <div class="col-sm-1"></div>
            <div class="col-sm-9 text-right"><a href="index.php?act=upload"> Back </a></div>
            <div class="col-sm-1 text-right"><a href="index.php?act=logout"> Logout </a></div>
            <div class="col-sm-1"></div>
        </div><br/>
    </div>
    <div class="col-sm-12">
        <div class="row">
            <div class="col-sm-1"></div>
            <form role="form" name="deleteproduct" id="deleteproduct" method="POST" action="index.php?act=deleteproduct" class="form-horizontal">
            <div class="col-sm-10">
                <div class="row">
                    <div class="col-sm-10">
                        <?php
                        if(isset($_GET['msg'])){
                            if($_GET['msg']==1){
                                echo "<div class='bg-success text-center'>You have successfully saved.</div><br/>";
                            }
                            if($_GET['msg']==0){
                                echo "<div class='bg-danger text-center'>You have not successfully saved.</div><br/>";
                            }
                            if($_GET['msg']==2){
                                echo "<div class='bg-success text-center'>You have successfully deleted.</div><br/>";
                            }
                            if($_GET['msg']==3){
                                echo "<div class='bg-danger text-center'>You have not successfully deleted.</div><br/>";
                            }
                            if($_GET['msg']==4){
                                echo "<div class='bg-success text-center'>You have successfully uploaded.</div><br/>";
                            }
                            if($_GET['msg']==5){
                                echo "<div class='bg-success text-center'>You have successfully uploaded in Magento.</div><br/>";
                            }
                            if($_GET['msg']==6){
                                echo "<div class='bg-info text-center'>Please select minimum one row.</div><br/>";
                            }
                        }
                        ?>
                    </div>
                    <div class="col-sm-2 text-center"><?php if(!empty($products)){ ?><button  class="btn btn-primary btn-md" type="submit" name="delete" value="delete">Delete</button><?php } ?></div>
                </div>
                <div class="row">
                    <div class="col-sm-12">

                        <div class="table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th class="text-center"><?php if(!empty($products)){ echo "<input type='checkbox' name='checkall' onclick='ToggleAll(this);'>"; } ?></th>
                                        <th class="text-center">Name</th>
                                        <th class="text-center">SKU</th>
                                        <th class="text-center">Status</th>
                                        <th class="text-center">Date & Time</th>
                                        <th class="text-center">Action</th>
                                    </tr>
                                </thead>
                                <tbody>

                                    <?php foreach($products as $product){ ?>
                                    <tr>
                                        <td class="text-center"><input name="checkbox[]" type="checkbox" value="<?php echo $product['product_id']; ?>"></td>
                                        <td class="text-center"><?php echo $product['name']; ?></td>
                                        <td class="text-center"><?php echo $product['sku']; ?></td>
                                        <td class="text-center"><?php echo $product['status']; ?></td>
                                        <td class="text-center"><?php echo $product['date_time']; ?></td>
                                        <td class="text-center"><a href="index.php?act=editproduct&id=<?php echo $product['product_id'];?>"> Edit</a></td>              
                                    </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12 text-center">
                        <?php if(!empty($products)){ ?>
                        <button  class="btn btn-default btn-md" type="submit" name="magento" value="magento">Magento Upload</button>
                        <?php } ?>                  
                    </div>
                </div>
            </div>
            </form>
            <div class="col-sm-1"></div>
        </div>
    </div>
    <div class="col-sm-12"><br/>
        <div class="row">
            <div class="col-sm-2"></div>
            <div class="col-sm-8 text-center space">
                <?php
                    for($i=1; $i<=$this->total_pages; $i++){
                        echo "<a href=index.php?act=product&page=".$i.">".$i."</a>";
                    }
                ?>
            </div>
            <div class="col-sm-2"></div>
        </div>
    </div>
</body>
</html>
<?php } 
}
?>

控制器\ product.php

<?php
include "model/login_class.php";
include "view/template/product_class.php";
$tplLogin=new LoginTpl();
$sqlLogin=new sqlLogin();

$total_results = $sqlLogin->totalproduct();
$per_page = 10;
$total_pages = ceil($total_results / $per_page);
$tplLogin->total_pages = $total_pages;
if (isset($_GET['page'])) {
    $show_page = $_GET['page']; //current page
    if ($show_page > 0 && $show_page <= $total_pages) {
        $start = ($show_page - 1) * $per_page;
        $end = $start + $per_page;
    } else {
        // error - show first set of results
        $start = 0;              
        $end = $per_page;
    }
} else {
    // if page isn't set, show first set of results
    $start = 0;
    $end = $per_page;
}
// display pagination
$sqlLogin->start = $start;
$sqlLogin->end = $end;
$products = $sqlLogin->product();
$tplLogin->products = $products;
$tplLogin->product();
?>

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以使用jQuery和Ajax执行此操作。 请参阅本教程issue 6401