php分页与动作按钮

时间:2017-11-13 09:39:15

标签: php mysql

我有以下PHP页面,它查询MYSQL TABLE并显示结果。

    <?php
    $host="localhost";
    $username="root";
    $password="PASSWORD"; // Mysql password
    $db_name="syslog"; // Database name
    $tbl_name="logs"; // Table name
    // Connect to server and select databse
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    //$sql="SELECT * FROM $tbl_name ORDER BY `LOGS` datetime LIMIT 0 , 10";
    $sql = "SELECT * FROM `logs`\n"
        . "ORDER BY `logs`.`datetime` DESC LIMIT 0, 50 ";
    $result=mysql_query($sql);
    // Define $host_column=1
    echo '<table width="1400" border="1" align="left" cellpadding="1" cellspacing="1">';
    echo '<tr><th>ID</th><th>Host</th><th>Date</th><th>Info</th><th>Type</th><th>Messgae</th></tr>';
    while($rows=mysql_fetch_array($result)){
    //$host_column assign here from result
    $host_column=$rows['host'];
// show alternate colors based on colum result
    $priority_column=$rows['priority'];
    if($priority_column=='err'){
    echo "<tr bgcolor='#FFA07A'><td>".$rows['seq']."</td><td>".$rows['host']."</td><td>".$rows['datetime']."</td><td>".$rows['priority']."</td><td>".$rows['program']."</td><td>".$rows['msg']."</td></tr>";
    }else if($host_column=='10.0.0.1'){
    echo "<tr bgcolor='#bbbbbb'><td>".$rows['seq']."</td><td>".$rows['host']."</td><td>".$rows['datetime']."</td><td>".$rows['priority']."</td><td>".$rows['program']."</td><td>".$rows['msg']."</td></tr>";
    }else if($host_column=='10.0.0.2'){
    echo "<tr bgcolor='#cccccc'><td>".$rows['seq']."</td><td>".$rows['host']."</td><td>".$rows['datetime']."</td><td>".$rows['priority']."</td><td>".$rows['program']."</td><td>".$rows['msg']."</td></tr>";
    }
    }
    echo '</table>';
    mysql_close();
    ?>

结果有数千个,因此我希望每页结果都有下一页选项,包括那里有多少页,下一页。另外我想在每一行上都有一个动作按钮,比如DELETE,EDIT,当我点击它时,它应该执行我选择的动作,比如转到另一个带动作的php删除/编辑这个条目号。我用简单的页面进行了分页,但是集成部分是我失败的地方加上添加动作按钮(或文本)

1 个答案:

答案 0 :(得分:0)

通过传递pageIndex和pageRecordCount,考虑在SQL端进行分页。

... LIMIT {pageIndex * pageRecordCount}, {pageRecordCount}