//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
$Limit=10;
$setLimit=0;
include("db.php");
$dbObj=new DB;
$sql="select * from category limit $setLimit,$Limit";
$results=$dbObj->GetSqlTable($sql);
$countsql="select * from category";
$numrow=$dbObj->GetSqlTable($countsql);
$numRow=count($numrow);//183
$numPage=ceil($numRow/$Limit);//19
//echo'<pre>';print_r($results);
?>
Show<select onchange="loadPagi(this.value)" align="left" id="loadppagi">
<?php for($i=10; $i<=100; $i+=10){?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php }?>
</select>Entries
<h3 align="center" style="color:#FF0066">Muna Pagination</h3>
<div id="displayTable">
<table align="center" border="1" cellpadding="1" style="background-color:#CCFF33" width="60%">
<tr>
<th>ID</th>
<th>Category Name</th>
<th>Category Order</th>
<th colspan="2">Action</th>
</tr>
<?php foreach($results as $result){?>
<tr>
<td><?php echo $result['id']; ?></td>
<td><?php echo $result['cat_name']; ?></td>
<td><?php echo $result['category_order']; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php }?>
</table>
<div align="center">
<?php for($i=1; $i<=$numPage;$i++){?>
<button "javascript:void(0)" onclick="midPages(<?php echo $i?>)" style="background-color:#FF99FF"><?php echo $i?></button>
<?php }?>
<button "javascript:void(0)" onclick="nextPages(1)" style="background-color:#CC33FF">Next</button>
</div>
</div>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
function onPage(p){
alert(p);
var limit=$("#loadppagi").val();
$.ajax({
type:"POST",
url:"middle.php",
data:{"limit":limit,"pageno":p},
success:function(data){
$("#displayTable").html(data);
}
});
}
function firstPages(f){
var limit=$("#loadppagi").val();
alert(f);
$.ajax({
type:"POST",
url:"middle.php",
data:{"pageno":f,"limit":limit},
success:function(data){
$("#displayTable").html(data);
}
});
}
function lastPages(l){
var limit=$("#loadppagi").val();
//alert(f);
$.ajax({
type:"POST",
url:"middle.php",
data:{"pageno":l,"limit":limit},
success:function(data){
$("#displayTable").html(data);
}
});
}
function nextPages(n){
n++;
alert(n);
var limit=$("#loadppagi").val();
//alert(limit);
$.ajax({
type:"POST",
url:"middle.php",
data:{"pageno":n,"limit":limit},
success:function(data){
$("#displayTable").html(data);
}
});
}
function prevPages(p){
alert(p);
p--;
var limit=$("#loadppagi").val();
//alert(limit);
$.ajax({
type:"POST",
url:"middle.php",
data:{"pageno":p,"limit":limit},
success:function(data){
$("#displayTable").html(data);
}
});
}
function midPages(i){
var limit=$("#loadppagi").val();
alert(limit);
$.ajax({
type:"POST",
url:"middle.php",
data:{"pageno":i,"limit":limit},
success:function(data){
$("#displayTable").html(data);
}
});
}
function loadPagi(t){
var pageno=1;
alert(pageno);
$.ajax({
type:"POST",
url:"middle.php",
data:{"limit":t,"pageno":pageno},
success:function(data){
$("#displayTable").html(data);
}
});
}
</script>
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// fetchmiddle.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
if(isset($_REQUEST['limit'])){
$Limit=$_REQUEST['limit'];
}
else {$Limit=10;}
if(isset($_REQUEST['pageno'])){
$pageno=$_REQUEST['pageno'];
$setLimit=($pageno-1)*$Limit;
}
else{$setLimit=0;}
include("db.php");
$dbObj=new DB;
$sql="select * from category limit $setLimit,$Limit";
$results=$dbObj->GetSqlTable($sql);
$countsql="select * from category";
$numrow=$dbObj->GetSqlTable($countsql);
$numRow=count($numrow);//183
$numPage=ceil($numRow/$Limit);//19
?>
<table align="center" border="1" cellpadding="1" style="background-color:#FFCCFF" width="60%">
<tr>
<th>ID</th>
<th>Category Name</th>
<th>Category Order</th>
<th colspan="2">Action</th>
</tr>
<?php foreach($results as $result){?>
<tr>
<td><?php echo $result['id']; ?></td>
<td><?php echo $result['cat_name']; ?></td>
<td><?php echo $result['category_order']; ?></td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php }?>
</table>
<div align="center">
<button "javascript:void(0)" onclick="firstPages(1)" style="background-color:#CC33FF">First</button>
<?php if($pageno>1){?>
<button "javascript:void(0)" onclick="prevPages(<?php echo $pageno?>)" style="background-color:#CC33FF">Prev</button>
<?php } ?>
<?php for($i=1; $i<=$numPage;$i++){?>
<button "javascript:void(0)" onclick="midPages(<?php echo $i?>);" style="background-color:#FF99FF"><?php if($i==$pageno){?> <font style="color:#FF0000" style="background-color:#FF9900"><strong><?php }?> <?php echo $i?></strong></font></button>
<?php }?>
<?php if($pageno<$numPage){?>
<button "javascript:void(0)" onclick="nextPages(<?php echo $pageno?>)" style="background-color:#CC33FF">Next</button>
<?php } ?>
<button "javascript:void(0)" onclick="lastPages(<?php echo $numPage?>)" style="background-color:#CC33FF">Last</button>
Page
<select onchange="onPage(this.value)" align="left" id="onPage">
<?php for($i=1; $i<=$numPage;$i++){?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php }?>
</select>
<br/>Showing Page: <?php echo $pageno?> of <?php echo $numPage?>
</div>
</div>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End fetchmiddle.php
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// db.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Digimagination Systems Library
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Database Functions
///////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Usage:
//// $db = new DB(); //instantiate using default read-only connection
//// $db = new DB($user,$pass); //instantiate using a specific login/pass
////
///////////////////////////////////////////////////////////////////////////////////////////////////
$showsql = true;
//$db = new DB();
class DB {
private $dbhost = "localhost";
private $dbuser = "root";
private $dbpass = "";
private $dbname = "ecommerce";
public $error = "";
function __construct()
{
}
//---------------
//foreach ($customers as $customer) {
// $row[0]=$customer->cust_name;
// $row[1]=$customer->monthly_income;
// array_push($rows,$row);
//}
//print json_encode($rows, JSON_NUMERIC_CHECK);
//---------------
public function ReportError ($sql, $message) {
//echo "SQL ERROR:\nMessage: $message\nSQL: $sql\n";
$this->error = $message;
}
//highchart
public function GetChart ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
$rows = Array();
while ($res = mysql_fetch_object($result)) //will ignore anything that comes after
{
$row[0]=$res->year;
$row[1]=$res->amount;
//$row[1]=$channel->Date;
array_push($rows,$row); //array_push(array,value1,value2...)
}
mysql_close($con);
//print_r($rows);
print_r(json_encode($rows, JSON_NUMERIC_CHECK));
}
//delete by muna
public function deleteRow($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
mysql_select_db($this->dbname, $con);
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
mysql_close($con);
return $result;
}
//by muna
public function GetSqlTable ($sql)
{
$data = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_array($result)) //will ignore anything that comes after
{
$data[] = $row;
}
mysql_close($con);
return $data;
}
public function InsertSql ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result) {$output= 1;}
else $output= 0;
mysql_close($con);
return $output;
}
//returns a 1d list of results (using the first column returned)
public function GetList2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
while ($row = mysql_fetch_array($result)) {
$results[] = $row[0];
}
mysql_close($con);
return $results;
}
public function GetRow2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
//mysql_select_db($this->dbname, $con);
mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
//echo $sql;
//var_dump($result);
//echo mysql_error($con);
//mysql_close($con);
return mysql_fetch_assoc($result);
}
public function GetDB ()
{
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con)
{
die("Could not connect to database!");
}
mysql_select_db($this->dbname, $con);
return $con;
}
public function Clean($sql)
{
return mysql_real_escape_string($sql, $this->GetDB());
}
public function Query ($sql)
{
$output=0;
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if (!isset($result))
{
return 0;
}
if (!$result) {return 0;}
if ($row = mysql_fetch_row($result))
{
$output = $row[0];
}
mysql_close($con);
return $output;
}
//returns the first two columns in an sql query as a keyed array
public function GetArray ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_row($result))
{
//verify there are two rows of data, otherwise return an indexed list of the first
$output[$row[0]] = $row[1];
}
mysql_close($con);
return $output;
}
//returns the first column of each row returned
public function GetList ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_row($result))
{
array_push($output, $row[0]);
}
mysql_close($con);
return $output;
}
public function GetResult ($sql)
{
$con = $this->GetDB();
if (!$con) {return 0;}
$result = mysql_query($sql, $con);
//mysql_close($con);
return $result;
}
public function GetJSON ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result); $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
mysql_close($con);
return json_encode($output);
}
public function GetTable ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result); $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
mysql_close($con);
return $output;
}
public function GetRow ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
if ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
$output = $row;
}
mysql_close($con);
return $output;
}
public function GetRowObject ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
if ($row = mysql_fetch_assoc($result)) //will ignore anything that comes after
{
$output = $row;
}
mysql_close($con);
return $output;
}
public function GetRows ($sql)
{
$output = Array();
$con = $this->GetDB();
if (!$con) {return -1;}
$result = mysql_query($sql, $con);
if ($result == 0) {return 0;}
while ($row = mysql_fetch_row($result)) //will ignore anything that comes after
{
array_push($output, $row);
}
mysql_close($con);
return $output;
}
public function Command ($sql)
{
global $showsql;
$this->error = "";
//if ($showsql) {echo "SQL: $sql\n";}
$con = $this->GetDB();
if (!$con) {return 0;}
$result = mysql_query($sql, $con);
$rows = mysql_affected_rows($con);
if ($rows < 1)
{
$this->error = mysql_error($con);
//$this->ReportError($sql, mysql_error($con));
//echo "DB ERROR: " . mysql_error($con) . "\n";
}
mysql_close($con);
return $rows;
}
}
?>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End db.php
///////////////////////////////////////////////////////////////////////////////////////////////////

No comments:
Post a Comment