放假前写了一个hbase的分页状况,现在来又修饰了一点,能显示传值过来的hbase名进行读写,根据每个页数来进行分页和实时的页数显示。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<style type="text/css">
body,table{
font-size:13px;
}
table{
/* table-layout:fixed;
empty-cells:show;
border-collapse: collapse;
margin:0 auto;
border:1px solid #cad9ea;
*/
table-layout:fixed;
border-collapse: collapse;
border:0px solid #cad9ea;
}
th{
height:22px;
font-size:13px;
font-weight:bold;
background-color:#CCCCCC;
text-align:center;
}
td{
color:#666;
font:bold 13px/15px
helvetica,arial,verdana,sans-serif;
backgroud-color:#f5f5f5;
height:20px;
}
.tableTitle{font-size:14px; font-weight:bold;}
.avb {
background-color: #99ffff;
}
.over {
background:#bcd4ec;
}
</style>
</style>
<link href="dist/css/bootstrap.css" rel="stylesheet"/>
<script src="dist/jquery-2.1.1.min.js"></script>
<script src="dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
var temptr = $();
$(function(){
$("#tableid").on("click","tr",function(event){
temptr.removeClass("avb");
temptr = $(this);
temptr.addClass("avb")
});
});
$(function(){
$("#tableid tr").mouseover(function(){
$(this).addClass("over");}).mouseout(function(){
$(this).removeClass("over");})
});
/*fuction GetData(data)
{
alert(data);
document.getElementById("id1").value=data;
}
*/
</script>
</head>
<body>
<div style="margin:0 auto;width:1500px; font-size:12px; line-height:20px;">
<div style="width:100%;height:30px; font-size:16px; font-weight:bold; text-align:center;">
<div style="right:auto;">
</div>
</div>
<?php
error_reporting(E_ALL^E_NOTICE);
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
use Thrift\Protocol\TBinaryProtocol;
use HBase\HBaseClient;
$GLOBALS['THRIFT_ROOT'] = './php/lib/Thrift';
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Transport/TTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Transport/TBufferedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Protocol/TProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Protocol/TBinaryProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Type/TMessageType.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Factory/TStringFuncFactory.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/StringFunc/TStringFunc.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/StringFunc/Core.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Type/TType.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Exception/TException.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Exception/TApplicationException.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Exception/TTransportException.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Exception/TProtocolException.php' );
require_once $GLOBALS['THRIFT_ROOT'].'/Types.php';
require_once $GLOBALS['THRIFT_ROOT'].'/Hbase.php';
$socket = new TSocket('172.16.27.12', '9090');
$socket->setSendTimeout(10000); // Ten seconds (too long for production, but this is just a demo ;)
$socket->setRecvTimeout(20000); // Twenty seconds
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new HbaseClient($protocol);
$con = mysql_connect('172.16.27.11','apt','123456');
mysql_select_db("apt", $con);
mysql_query("SET NAMES UTF8",$con);
$transport->open();
//$table_name = 'test';
//$table_name = $_GET['q'];
//setcookie('mycookie1',$table_name);
//$table_name = "snort";
session_start();
if(isset($_GET['q']))
{
$_SESSION['q'] = $_GET['q'];
$table_name = $_GET['q'];
}
elseif(isset($_SESSION['q']))
{
$table_name = $_SESSION['q'];
}
echo "$table_name";
$start_row = "";
$family = array( "$table_name" );
$attributes = array ();
$scanner = $client->scannerOpen( $table_name, $start_row , $family , $attributes );
?>
<table id="tableid" class="table table-bordered">
<span display:block;width:110px;height:40px;></span>
<span hover{background:0 -40px;}></span>
<thead>
<th align="center">Classification</th>
<th align="center">Priority</th>
<th align="center">dst_ip</th>
<th align="center">message</th>
<th align="center">plugin_id</th>
<th align="center">plugin_sid</th>
<th align="center">protocal</th>
<th align="center">src_ip</th>
<th align="center">time</th>
<th align="center">dsp_port</th>
<th align="center">src_port</th>
</thead>
<?php
if(!$_GET['page'])
$page=1;
else
$page=$_GET['page'];
$list_num=5;
//$n=0;
$i = 1;
while (true)
{
$get_arr = $client->scannerGet( $scanner );
if($get_arr == null) break;
if($i<($page-1)*$list_num +1 || $i > $page*$list_num)
{
//echo "asdfasdf".$i;
//$n++;
$i++;
$num++;
continue;
}
foreach ( $get_arr as $TRowResult )
{
echo '<tr style="height:53px">';
$column = $TRowResult->columns;
foreach ($column as $family_column=>$Tcell){
echo '<td align="center"><b>';
echo (" {$Tcell->value} ");
echo '</td>';
}
echo '</tr>';
}
//$n++;
$i++;
$num++;
}
echo $num;
echo "<p align=\"center\">";
echo "目前共有".$num."条记录 ";
$p_count=ceil($num/$list_num);
echo "共分".$p_count."页显示 ";
echo "当前显示第".$page."页";
echo "<p>";
$prev_page=$page-1;
$next_page=$page+1;
echo "<p align=\"center\">";
if ($page<=1)
{
echo "第一页 |";
}
else
{
echo "<a href='TryAgain2.php?page=1'>第一页</a> |";
}
if ($prev_page<1)
{
echo "上一页 |";
}
else
{
echo "<a href='TryAgain2.php?page=$prev_page'>上一页</a> |";
}
if ($next_page>$p_count)
{
echo "下一页 |";
}
else
{
echo "<a href='TryAgain2.php?page=$next_page'>下一页</a> |";
}
if ($page>=$p_count)
{
echo "最后一页</p>\n";
}
else
{
echo "<a href='TryAgain2.php?page=$p_count'>最后一页</a></p>\n";
}
$client->scannerClose( $scanner );
$transport->close();
?>
</table>
</div>
</body>
</html>