jQuery & PHP and MYSQL IE Problem - php

Now All of this code works fine in Firfox but in IE the divs dont change when the php infomation changes.
Can some one help me please as i am working on a project and this is holding me back
Thank you.
Here is the jQuery Code:
$.ajaxSetup({ cache: false });
$(document).ready(function(){
$("#not").css('display','none');
$("#fonline").css('display','none');
$("#not").hide();
$("#fonline").hide();
$("#shfm").click(function () {
$("#not").hide();
$("#fonline").toggle();
});
$("#notifi").click(function () {
$("#fonline").hide();
$("#not").toggle();
});
});
function closeboxes() {
$("#fonline").hide();
$("#not").hide();
}
function loadContent(id) {
$("#contentArea").load("notifications.php?o="+id+"");
};
$(document).ready(function() {
$("#settings").toggle(
function () {
$(this).html('X Close');
},
function () {
$(this).html('Settings');
}
);
});
function FriendsContent(id) {
$("#fArea").load("friends_online.php?fo="+id+"");
};
$(document).ready(function() {
$("#Options").toggle(
function () {
$(this).html('X Close');
},
function () {
$(this).html('Options');
}
);
});
var refreshId = setInterval(function()
{
$('#fArea').fadeOut("slow").load('response.php').fadeIn("slow");
}, 10000);
PHP Code:
$cOption = $_GET['fo'];
switch($cOption) {
case 1:
$recordsPerPage = 5;
$pageNum = 1;
if(isset($_GET['pg'])) {
$pageNum = $_GET['pg'];
settype($pageNum, 'integer');
}
echo "<table width='98%' border='0' cellspacing='0' cellpadding='0'>";
$offset = ($pageNum - 1) * $recordsPerPage;
$onlineresult = mysql_query("SELECT * FROM online") or die (mysql_error());
while ($ousers = mysql_fetch_array($onlineresult)) {
$onuid = $ousers['uid'];
$flist = mysql_query("SELECT * FROM friends_list WHERE fid='$onuid' AND uid='$myid' LIMIT $offset, $recordsPerPage;") or die (mysql_error());
while ($fri = mysql_fetch_array($flist)) {
$id = $fir['id'];
$uid = $fri['uid'];
$fid = $fri['fid'];
$userinfomation = mysql_query("SELECT * FROM accounts WHERE id='$fid'");
$userinfo = mysql_fetch_array($userinfomation);
$v_tgid = $userinfo['tgid'];
echo "
<tr class='menutxt2'>
<td width='11%' height='21'><center>
</center></td>
<td width='50%'>$v_tgid</td>
<td width='39%'>View Profile</td>
</tr>
";
}
}
echo "</table>";
$query = "SELECT COUNT(id) AS id FROM friends_list;";
$result = mysql_query($query) or die('Mysql Err. 2');
$row = mysql_fetch_assoc($result);
$numrows = $row['id'];
$maxPage = ceil($numrows/$recordsPerPage);
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= "<span class='menutxt'>Pages: $page </span>";
}
else
{
$nav .= "";
}
}
if ($pageNum > 1) {
$page = $pageNum - 1;
$prev = "";
$first = "";
}
else {
$prev = '';
$first = '';
}
if ($pageNum < $maxPage) {
$page = $pageNum + 1;
$next = "";
$last = "";
}
else {
$next = '';
$last = '';
}
echo "$first <b>$prev</b> $nav<b> $next</b> $last";
echo "
";
break;
case 2:
echo 'Options';
break;
default:
echo 'Whoops, didn\'t understand that option: <i>'.$cOption.'</i>';
}

IE tends to cache ajax requests when you don't want it to. The .load() towards the end of your code is issuing a GET request which IE is probably caching instead of fetching from the server.
http://www.sitecrafting.com/blog/ajax-ie-caching-issues/
google search 'ie cache ajax jquery'

Related

how to use the variable from if isset $_POST output?

How do I use the value of variable $dd i.e 10 or 100000 outside the if condition?
I want to show that status(available/not available) and the $dd value in separate locations.
ajax success
success: function (response) {
$("#uname_response").html(response);
}
if(isset($_POST['applied_promocode'])){
$applied_promocode = $_POST['applied_promocode'];
$dd = 0;
// Check applied_promocode
$stmt = $dbh->prepare("SELECT count(*) as cntUser FROM coupon WHERE applied_promocode=:applied_promocode");
$stmt->bindValue(':applied_promocode', $applied_promocode, PDO::PARAM_STR);
$stmt->execute();
$count = $stmt->fetchColumn();
//Availability message
if($count > 0){
$response = "<span style='color: red;'>Not Available.</span>";
$dd = 10;
} else {
$response = "<span style='color: green;'>Available.</span>";
$dd = 100000;
}
echo $dd;
echo $response;
exit;
}
$discount_price = $dd * 100;
You can choose to send back data in JSON format if you want to be able to pass complex data (i.e. non-string value). The way to do that would be as follows:
Untested code
if($count > 0){
$response = "Not Available";
$dd = 10;
} else {
$response = "Available";
$dd = 100000;
}
$discount_price = $dd * 100;
$json_data = array('response'=>$response, 'dd' => $discount_price);
echo json_encode($json_data);
Then on the client side, you can use something like this:
success: function (response) {
var json_data = JSON.parse(response);
var color = "red";
if(json_data.response == 'Available')
{
color = "green";
}
var html = "<span style='color: "+color+";'>"+json_data.response+".</span><p>"Discounted price = "+json_data.dd+"</p>";
$("#uname_response").html(html);
}
Or if you do not like concatenation, use the traditional approach to manipulate the DOM
success: function (response) {
var json_data = JSON.parse(response);
if(json_data && json_data.response)
{
var color = "red";
if(json_data.response == 'Available')
{
color = "green";
}
var span = document.createElement('span');
span.style.color = color;
span.innerHTML = json_data.response;
var p = document.createElement('p');
p.innerHTML = "Discounted price is "+json_data.dd;
var div = document.createElement('div');
div.appendChild(span);
div.appendChild(p);
$("#uname_response").html(div);
}
else
{
alert("Invalid data returned from server");
}
}

PHP PDO Pagination not refreshed

im quite new to PHP and im trying to make a pagination, the code works! but i need to click on the button twice to make the page refreshed/change. how do i fix this?
view/main/user/userlist.php
<?php
$_SESSION['pagelim'] = 10;
$_SESSION['page'] = $_GET['halaman'];
if ($_SESSION['page'] == '') {
$_SESSION['pos'] = 0;
$_SESSION['page'] = 1;
} else {
$_SESSION['pos'] = ($_SESSION['page']- 1) * $_SESSION['pagelim'];
}
$itemcount = listpetugas::getlisted();
$pagecount = ceil(listpetugas::getlisted()/$_SESSION['pagelim']);
for ($i=1;$i<=$pagecount;$i++)
{ ?>
<?php
if ($i!=$pagecount){
echo " <ul class='pagination'><li><a href='?controller=main&action=userlist&halaman=$i' onclick='myFunction()'>$i</a></li></ul>";?>
<?php }
else{
echo "$i";
} ?>
<?php } ?>
model/userdb.php
public static function listemup()
{
if ($_SESSION['pos'] =='' && $_SESSION['pagelim'])
{
$pos = 0;
$lim = 10;
}
else {
$pos = $_SESSION['pos'];
$lim = $_SESSION['pagelim'];
}
$list = [];
$db = FirstFire::StartConnection();
$req = $db->query("SELECT * FROM randomity LIMIT $pos,$lim");
$rowcount = $req->rowCount();
foreach ($req->fetchAll() as $post) {
$list[] = new listpetugas($post['name'],$post['email'],$post['adress'],$post['wow']);
}
return $list;
}
JS
<script>
function myFunction() {
location.reload();
}
</script>
sorry for the messy code.

Flash Database Operation Failed

I have a problem with my Flash (.fla) project. I've connected my flash with database with php script. I used ActionScript 2.0.
The problem is data can show at compile program on AdobeFlash CS6 (CTRL+Enter) but data cant show in datagrid when I open the .swf.
It's my php script
<?php
mysql_pconnect ("localhost", "root", "");
mysql_select_db ("modul");
$qr = mysql_query("SELECT * from nilaisiswa");
if (!qr || mysql_num_rows($qr)==0) {
$r_string = '&errorcode=3&msg='.mysql_error().'&';
} else {
$r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
$i = 0;
while ($row = mysql_fetch_assoc ($qr)) {
while (list ($key, $val) = each ($row)) {
$r_string .= '&' . $key . $i . '=' . stripslashes($val);
}
$i++;
}
$r_string .='&';
}
echo $r_string;
?>
And here it's my ActionScript 2.0
var select_lv:LoadVars = new LoadVars();
var insert_lv:LoadVars = new LoadVars();
var delete_lv:LoadVars = new LoadVars();
var today:Date = new Date();
var deleteIndex:Number;
var errorMsgs:Array = [
"",
"Couldn't connect to server",
"Couldn't connect to database",
"Error running query",
"First four entries may not be deleted"];
var filepath:String;
var scoreInfo:Array = [];
var headerListener:Object = {};
headerListener.headerRelease = function(event:Object) {
switch (event.columnIndex) {
case 0:
if (scores_dg.getColumnAt(0).sortedUp) {
scores_dg.sortItemsBy(scores_dg.columnNames[0], Array.CASEINSENSITIVE | Array.DESCENDING);
} else {
scores_dg.sortItemsBy(scores_dg.columnNames[0], Array.CASEINSENSITIVE);
}
scores_dg.getColumnAt(0).sortedUp = !scores_dg.getColumnAt(0).sortedUp;
break;
case 1:
if (scores_dg.getColumnAt(1).sortedUp) {
scores_dg.sortItemsBy(scores_dg.columnNames[1], Array.NUMERIC | Array.DESCENDING);
} else {
scores_dg.sortItemsBy(scores_dg.columnNames[1], Array.NUMERIC);
}
scores_dg.getColumnAt(1).sortedUp = !scores_dg.getColumnAt(1).sortedUp;
break;
}
}
function zerofill(n:Number):String {
if (n<10) return '0' + n.toString();
else return n.toString();
}
filepath = "http://localhost/tesis/";
nickname_ti.maxChars = 50;
date_ti.maxChars = 10;
score_ti.text = 0;
date_ti.text = today.getDate() + '-' + zerofill(today.getMonth()+1) + '-' + zerofill(today.getFullYear());
select_lv.onLoad = function(ok:Boolean) {
if (ok) {
if (this.errorcode=="0") {
for (var i:Number=0; i < this.n; i++) {
scoreInfo.push(
{record:this["id"+i],
nickname:this["nickname"+i],
score:Number(this["score"+i]),
dateposted:this["dateposted"+i]
});
}
scores_dg.columnNames = ["nickname", "score", "dateposted"];
scores_dg.getColumnAt(0).width = 130;
scores_dg.getColumnAt(0).sortOnHeaderRelease = false;
scores_dg.getColumnAt(0).sortedUp = false;
scores_dg.getColumnAt(0).headerText = "Nickname";
scores_dg.getColumnAt(1).width = 130;
scores_dg.getColumnAt(1).sortOnHeaderRelease = false;
scores_dg.getColumnAt(1).sortedUp = false;
scores_dg.getColumnAt(1).headerText = "Score";
scores_dg.getColumnAt(2).width = 130;
scores_dg.getColumnAt(2).headerText = "Date Posted";
scores_dg.dataProvider = scoreInfo;
scores_dg.addEventListener("headerRelease", headerListener);
msg_ta.text = "Enter data and click Add to add a score.";
} else {
msg_ta.text = errorMsgs[Number(this.errorcode)];
if (this.errorcode == "3") msg_ta.text += ": " + this.msg;
}
} else {
msg_ta.text = "Flash-database select operation failed";
}
}
msg_ta.text = "Getting high scores from database...";
select_lv.sendAndLoad(filepath + "getscores.php", select_lv, "GET");

After adding pagination PHP function no longer displays mysql array data

I have made a PHP function that pulls data from a table (product_reviews) in my database, showing all reviews for a unique product_id. Here is the code:
function showReviews ($product_id)
{
include('database_conn.php');
$query = "SELECT * FROM product_reviews WHERE product_reviews.productID='".$product_id."'";
if ($queryresult = mysqli_query($conn, $query))
{
while ($currentrow = mysqli_fetch_assoc($queryresult))
{
$result_list[] = $currentrow;
}
foreach ($result_list as $currentrow)
{
$productitems[] = array(
$customer_forename = $currentrow['customer_forename'],
$customer_surname = $currentrow['customer_surname'],
$review_title = $currentrow['review_title'],
$review_text = $currentrow['review_text']);
echo '<article class="Review_Box">';
echo "<h3>".$review_title." by ".$customer_forename." ".$customer_surname."</h3></br>";
echo "<p>".$review_text."</p>";
echo "</article>";
}
}
}
This function is then called from the products page and it works as intended.
But when I add pagination to the function ( following an ehow tutorial), the function doesn't have any output(see here).
if(!function_exists('showReviews'))
{
function showReviews ($product_id)
{
include('database_conn.php');
include('functions.php');
$rowsPerPage = 3;
$currentPage = ((isset($_GET['page']) && $_GET['page'] > 0) ? (int)$_GET['page'] : 1);
$offset = ($currentPage-1)*$rowsPerPage;
$query = "SELECT * FROM product_reviews WHERE product_reviews.productID='".$product_id."' LIMIT '".$offset."','".$rowsPerPage."'";
if ($queryresult = mysqli_query($conn, $query))
{
while ($currentrow = mysqli_fetch_assoc($queryresult))
{
$result_list[] = $currentrow;
}
foreach ($result_list as $currentrow)
{
$productitems[] = array(
$customer_forename = $currentrow['customer_forename'],
$customer_surname = $currentrow['customer_surname'],
$review_title = $currentrow['review_title'],
$review_text = $currentrow['review_text']);
echo '<article class="Review_Box">';
echo "<h3>".$review_title." by ".$customer_forename." ".$customer_surname."</h3></br>";
echo "<p>".$review_text."</p>";
echo "</article>";
}
}
$count = countReviews (1);
$totalPages = $count/$rowsPerPage;
if($currentPage > 1)
{
echo 'Previous Page ';
}
if($currentPage < $totalPages)
{
echo 'Next Page';
}
}
}
I tested my sql query and it works fine in mysql Workbench.
What am I doing wrong? Can anyone recommend a better way to do this?
When you create your query, you are encapsulating the offset and limit between single quotes (if I read your code correctly).
SELECT * FROM product_reviews WHERE product_reviews.productID='25' LIMIT '0','3'
Try removing those single quotes.

Pagination with $this->db->query() and $this->db->limit()

I tried the following code for pagination but it not works for me it not shows 10 records per page it shows all records on the single page and again same number of records shows on the next page my code in controller
<?php
class Classified_detail extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Jobseekermodel','',TRUE);
//$this->load->database($config);
//$secound_db= $this->load->database('classified_db', TRUE);
//$CI = &get_instance();
$this->db2 = $this->load->database('classified_db', TRUE); //doolaly
$this->load->model('Emailmodel','',TRUE);
$this->load->model('Bookmodel','',TRUE);
$this->load->model('Consultantmodel','',TRUE);
$this->load->model('Openingmodel','',TRUE);
//$this->load->model('classified/Mobile_model','',TRUE);
$this->load->model('classified/classified_ad','',TRUE);
$this->load->model('classified/create_ad','',TRUE);
$this->load->model('Commfuncmodel','',TRUE);
$this->lang->load('message', 'english');
$this->lang->load('mail', 'english');
$this->load->library('form_validation');
if (session_id() == "") session_start();
}
/***********************Start of Function For Showing list of ebooks from database **********************************/
function index($msg=NULL)
{
$this->Commfuncmodel->checkJobseekerLogin();
//******My expired ads*******/
//post ad history
$_SESSION["ex_ad_paging"] = PER_PAGE_RECORDS;
$today = date('Y-m-d');
$qry ="select AM.Ad_Title as Title,AM.Advertizement_Text as Description,AM.Price,AMP.Expiry_Date
from ad_mobile_phones AM inner join ad_mobilephone_plan_mapping AMP on
AM.Ad_ID=AMP.Ad_ID
where AM.Created_By='".$_SESSION['jobseeker_id']."' and AMP.Expiry_Date <'".$today."'
UNION
select A.Title,A.Description,A.Price,B.Expiry_Date from ad_vehicle A inner join ad_vehicle_plan_mapping B
on A.Ad_ID = B.Ad_ID where A.Created_By ='".$_SESSION['jobseeker_id']."' and B.Expiry_Date <'".$today."'";
$query=$this->db->query($qry);
$ex_ed_count=$query->num_rows();
$ex_ad_data=$query->result_array();
/******************Start of Pagination****************/
$segments = array('classified/classified_detail','index/my_ex_ads');
$url_name=site_url($segments);
$ex_ed_count = count($ex_ad_data);
$per_page_records=((#$_SESSION["ex_ad_paging"]=="All")?$ex_ed_count:#$_SESSION["ex_ad_paging"]);
$expagination=$this->Commfuncmodel->pagination_a($ex_ed_count,$this->uri->segment(5),$per_page_records,$url_name,"1","EXAD");
/******************End Pagination******************/
if($this->uri->segment(4)== "my_ex_ads")
{
$page_no=(int)$this->uri->segment(5);
if( empty($page_no) || ( $page_no <1 ) )
$nextrecord = 0 ;
else
$nextrecord = ($page_no-1) * #$_SESSION["ex_ad_paging"] ;
}
if($_SESSION["ex_ad_paging"]!="All")
{
$limit_start=$nextrecord;
$limit_end=$_SESSION["ex_ad_paging"];
}
else
{
$limit_start=0;
$limit_end=$ex_ed_count;
}
$qry ="select AM.Ad_Title as Title,AM.Advertizement_Text as Description,AM.Price,AMP.Expiry_Date
from ad_mobile_phones AM inner join ad_mobilephone_plan_mapping AMP on
AM.Ad_ID=AMP.Ad_ID where AM.Created_By='".$_SESSION['jobseeker_id']."' and AMP.Expiry_Date <'".$today."'
UNION
select A.Title,A.Description,A.Price,B.Expiry_Date from ad_vehicle A inner join ad_vehicle_plan_mapping B
on A.Ad_ID = B.Ad_ID where A.Created_By ='".$_SESSION['jobseeker_id']."' and B.Expiry_Date <'".$today."'";
//$this->db->limit(#$limit_end,#$limit_start);
//var_dump($limit_end);
//var_dump($limit_start);
$query=$this->db->query($qry);
$this->db->limit(#$limit_end,#$limit_start);
//var_dump($query);
$my_ad_data=$query->result_array();
//old data
//$this->db2->where('Expiry_Date' < $date);
// $this->db2->limit(#$limit_end,#$limit_start);
//$query=$this->db2->get(ad_mobilephone_plan_mapping);
// $my_ad_data=$query->result_array();
//follw up
$i=0;
if($query->num_rows()>0)
{
foreach($my_ad_data as $item => $v)
{
//$my_ad_data[$i]['applied_js']="y";
//follow up mail sent
//$this->db2->where("Ad_ID",$my_ad_data[$i]['Ad_ID']);
//$this->db2->where('Expiry_Date' < $date);
//$query=$this->db2->get(ad_mobilephone_plan_mapping);
//var_dump($fquery);
//$my_ad_data[$i]['count'] = $fquery->num_rows();
$qry ="select AM.Ad_Title as Title,AM.Advertizement_Text as Description,AM.Price,AMP.Expiry_Date
from ad_mobile_phones AM inner join ad_mobilephone_plan_mapping AMP on
AM.Ad_ID=AMP.Ad_ID where AM.Created_By='".$_SESSION['jobseeker_id']."' and AMP.Expiry_Date <'".$today."'
UNION
select A.Title,A.Description,A.Price,B.Expiry_Date from ad_vehicle A inner join ad_vehicle_plan_mapping B
on A.Ad_ID = B.Ad_ID where A.Created_By ='".$_SESSION['jobseeker_id']."' and B.Expiry_Date <'".$today."'";
$fquery = $this->db->query($qry);
//var_dump($fquery);
//var_dump($my_ad_data[$i]['count']);
$my_ad_data[$i]['count'] = $fquery->num_rows();
if($fquery->num_rows() < 2)
{
$my_ad_data[$i]['sent_follow']="y";
}
$oid = substr($my_ad_data[$i]['opening_id'],-9);
$my_ad_data[$i]['oid'] = substr($oid,0,-1);
$i++;
}
}
$data['acc'] = 'acc';
$data['page_no'] = $page_no;
$data['ex_ad_data'] = $my_ad_data;
$data['ex_ed_count'] = $ex_ed_count;
$data['expagination'] =$expagination;
$data['nextrecord'] = $nextrecord;
$data['msg_display'] =$msg_display;
$data['view_file'] = 'classified/account';
if($this->uri->segment(4)=="h")
{
$data['ajax'] = 1;
$this->load->view('account/historylist',$data);
}
else if($this->uri->segment(4)=="my_ads")
{
$data['ajax'] = 1;
$this->load->view('classified/classified_ads',$data);
}
else if($this->uri->segment(4)=="my_ex_ads")
{
$data['ajax'] = 1;
$this->load->view('account/expired_ads',$data);
}
else if($this->uri->segment(4)=="job")
{
$data['ajax'] = 1;
$this->load->view('account/joblist',$data);
}
else
{
$this->load->view('classified/classified_layout',$data);
}
}
Please help me and thanks in advance
Model Commfuncmodel.php
<?php
class Commfuncmodel extends CI_Model
{
function __construct()
{
parent::__construct();
//$this->load->model('Adminmodel','',TRUE);
}
function getcounter($tblnm,$id,$val)
{
$this->db->select('counter');
$this->db->where($id,$val);
$query = $this->db->get($tblnm);
$data=$query->result_array();
return $data[0];
}
function setcounter($tblnm,$id,$val)
{
$cnt = $this->getcounter($tblnm,$id,$val);
$data['counter'] = $cnt['counter'] + 1;
$this->db->where($id, $val);
$this->db->update($tblnm,$data);
return true;
}
/**************************PAGINATION FUNCTION START*************************************/
function pagination($total_rec, $current_page=0, $perPage, $url_name)
{
$pagination = "" ;
//echo $current_page;
// if total records are less than per page record then dont show pagination
if($total_rec<= $perPage)
{
return ;
}
// Retrieve Current Page number
if($current_page < 0 || $current_page==0)
{
$p = 1 ;
}
else
{
$p = $current_page ;
}
// Calculate Total Pages
$total_pages = (int)($total_rec/$perPage) ;
if( ($total_rec%$perPage) > 0 )
{
$total_pages++ ;
}
//echo "total pages ".$total_pages;
//echo "p is ".$p;
// To show pagination
if($total_pages >= 1)
{
$pagination .= '<ul class="pagination" style="margin-left:150px;">';
//$pagination .= "<br>Showing Page ".$p." of ".$total_pages."<br>";
// FIRST & PRIV LINKS
if($p>1)
{
//$pagination .= "<a href='".$url_name."/1'>"."First"."</a> " ;
$pagination .= "<li><a style='color: #000;' href='".$url_name."/". ($p-1) ."'>"." Prev"."</a></li>" ;
}
// Middle links..
if( ($p%BEFORE_AFTER_NO) == 0)
{
if( ($total_pages - $p) > BEFORE_AFTER_NO)
{
$start = $p-BEFORE_AFTER_NO ? $p-BEFORE_AFTER_NO:1 ;
}
else
{
$start = $total_pages - TOTAL_PAGINATION_NO;
if($start <= 0)
{
$start = 1 ;
}
}
$end = $p+BEFORE_AFTER_NO ;
}
else
{
if($p > 9)
{
if( ($total_pages - $p) > BEFORE_AFTER_NO)
{
$start = $p - BEFORE_AFTER_NO ;
}
else
{
$start = $total_pages - TOTAL_PAGINATION_NO;
}
$end = $p + BEFORE_AFTER_NO ;
}
else
{
$start = 1 ;
$end = TOTAL_PAGINATION_NO;
}
}
for($i=$start; $i<=$end && $i<=$total_pages;$i++)
{
if($i==$p)
{
$pagination .= '<li class="active">'.$i.'</li>' ;
}
else
{
$pagination .= "<li><a style='color: #000;' href='".$url_name."/". $i ."'>".$i."</a></li>" ;
}
}
// NEXT & LAST links
if($p>=1 && $p<$total_pages)
{
$pagination .= "<li ><a style='color: #000;' href='".$url_name ."/". ($p+1) ."'>"."Next"."</a></li>" ;
//$pagination .= "<a href='".$url_name ."/$total_pages'>"."Last"."</a> " ;
}
} // if($total_pages>1) end.
$pagination .='</ul>' ;
return ($pagination) ;
}
function pagination_a($total_rec, $current_page=0, $perPage, $url_name,$ajaxflag=NULL,$d)
{
$pagination = "" ;
// if total records are less than per page record then dont show pagination
if($total_rec<= $perPage)
{
return ;
}
// Retrieve Current Page number
if($current_page<0 || $current_page==0)
{
$p = 1 ;
}
else
{
$p = $current_page ;
}
// Calculate Total Pages
$total_pages = (int)($total_rec/$perPage) ;
if( ($total_rec%$perPage) > 0 )
{
$total_pages++ ;
}
// To show pagination
if($total_pages >= 1)
{
$pagination .= '<ul class="pagination" style="margin-left:227px;">';
// FIRST & PRIV LINKS
if($p>1)
{
if($ajaxflag)
{
//$pagination .= "<a href=javascript:ajaxPagination('".$url_name."/1')>".lang("FIRST")."</a> " ;
$pagination .= "<li><a href=javascript:ajaxPagination('".$url_name."/". ($p-1) ."/".$d."')>"."PREV"."</a></li>" ;
}
else
{
//$pagination .= "<a href='".$url_name."/1'>".lang("FIRST")."</a> " ;
$pagination .= "<li><a href='".$url_name."/". ($p-1) ."'>"."PREV"."</a></li>" ;
}
}
// Middle links..
//echo $total_pages;
if( ($p%BEFORE_AFTER_NO) == 0)
{
if( ($total_pages - $p) > BEFORE_AFTER_NO)
{
$start = $p-BEFORE_AFTER_NO ? $p-BEFORE_AFTER_NO:1 ;
}
else
{
$start = $total_pages - TOTAL_PAGINATION_NO;
if($start <= 0)
{
$start = 1 ;
}
}
$end = $p+BEFORE_AFTER_NO ;
}
else
{
if($p > 9)
{
if( ($total_pages - $p) > BEFORE_AFTER_NO)
{
$start = $p - BEFORE_AFTER_NO ;
}
else
{
$start = $total_pages - TOTAL_PAGINATION_NO;
}
$end = $p + BEFORE_AFTER_NO ;
}
else
{
$start = 1 ;
$end = TOTAL_PAGINATION_NO;
}
}
for($i=$start; $i<=$end && $i<=$total_pages;$i++)
{
if($i==$p)
{
$pagination .= '<li class="active"><a class="page-links" id="current">'.$i.'</a></li> ' ;
}
else
{
if($ajaxflag)
$pagination .= "<li><a href=javascript:ajaxPagination('".$url_name."/". $i ."/".$d."')>$i</a></li>" ;
else
$pagination .= "<li><a href='".$url_name."/". $i ."'>$i</a></li>" ;
}
}
// NEXT & LAST links
if($p>=1 && $p <$total_pages)
{
if($ajaxflag)
{
$pagination .= "<li><a href=javascript:ajaxPagination('".$url_name ."/". ($p+1) ."/".$d."')>"."NEXT"."</a></li>";
//$pagination .= "<a href=javascript:ajaxPagination('".$url_name ."/$total_pages')>".lang("LAST")."</a> " ;
}
else
{
$pagination .= "<li><a href='".$url_name ."/". ($p+1) ."'>"."NEXT"."</a></li>";
//$pagination .= "<a href='".$url_name ."/$total_pages'>".lang("LAST")."</a> " ;
}
}
} // if($total_pages>1) end.
$pagination .='</ul>';
//echo $pagination;
return ($pagination) ;
}
}
?>

Categories