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) ;
}
}
?>
Related
my client ask me to show the in and out of their employees from biometrics..i already did it but it only shows data for 1 day. Can somebody help me..If you can see I had a lot of codes there and it doesn't satisfy my client.I'am working on it for almost a month
this is my code..I'm a beginner.
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_REQUEST['startdate']) && isset($_REQUEST['enddate']))
{
$startdate = $_REQUEST['startdate'];
$enddate = $_REQUEST['enddate'];
$shiftdate = $_REQUEST['shiftdate'];
$category= $_REQUEST['category'];
$counterless = 0;
$ncounter = 0;
$count =0 ;
$loop=0;
$holder=0;
$checker=0;
$wala = 0;
$present = 0;
/*$_SESSION['nightname'] = array();
$_SESSION['nighttime'] = array();
$_SESSION['testname'] = array();
$_SESSION['testtime'] = array();*/
$con = mysqli_connect("localhost","root","","testingdb");
$connect = mysqli_connect("localhost","root","","inoutchecking");
mysqli_query($con,"delete from forprint");
mysqli_query($con,"delete from absentforprint");
$result = mysqli_query($con,"select * from wawart where Column_2 = '$startdate' order by Column_2 asc");
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result))
{
$time = $row['Column_3'];
$times = (int)($time);
$inout = $row['Column_4'];
$dates = $row['Column_2'];
if(($times <= 14 and $inout == '1') or ($times >=17 and $inout == '4'))
{
$_SESSION['testname'][$counterless] = $row['Column_1'];
$_SESSION['testtime'][$counterless] = $time;
$counterless++;
}
if(($times <= 20 and $times >= 15) and $inout == '1')
{
$_SESSION['nightname'][$ncounter] = $row['Column_1'];
$_SESSION['nighttime'][$ncounter] = $time;
$ncounter++;
}
}
$wala=1;
}
else
{
$wala=0;
}
if($category == 'dayshift')
{
$shift = 'Day Shift';
}
else if($category == 'nightshift')
{
$shift = 'Night Shift';
}
else
{
$shift = 'Night Shift and Day Shift';
}
echo "<label class='cat'>".$shift."</label>";
echo "<label class='absent'>Absentees ".$startdate."</label>";
if($category == 'dayshift')
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th><th>DATE</th><th>IN</th><th>OUT</th></tr>";
for($x = 0; $x<$counterless;$x++)
{
$dempid = $_SESSION['testname'][$x];
$day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$count++;
if($loop == '1')
{
echo "<td>NO OUT</td></tr>";
$loop=0;
}
$empid = $empinfo['empid'];
$empshift = $empinfo['shift'];
$name = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
$checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
if($holder == $empinfo['empid'])
{
break;
}
echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
if(mysqli_num_rows($checking)>0)
{
while($row=mysqli_fetch_array($checking))
{
$time = $row['Column_3'];
$times = (int)$time;
if($holder == $empinfo['empid'])
{
break;
}
else
{
$inout = $row['Column_4'];
$time = $row['Column_3'];
if($loop ==0)
{
$date = $row['Column_2'];
echo"<td>".$row['Column_2']."</td>";
}
if($loop ==0 )
{
if($inout == '1')
{
$timein = $time;
echo "<td>".$time."</td>";
$loop = 1;
}
if($inout == '4')
{
$timein = 'NO IN';
$timeout = $time;
echo "<td><B>NO IN</td><td>".$time."</td></tr>";
$holder = $empinfo['empid'];
$loop = 0;
}
}
else
{
if($loop =='1' && $inout == '4')
{
$timeout = $time;
echo "<td>".$time."</td></tr>";
}
if($loop =='1' && $inout == '1')
{
$timeout = 'NO OUT';
echo "<td><B>NO OUT</td></tr>";
}
$loop = 0;
$counter = 0;
$holder = $empinfo['empid'];
$checker = 2;
if($checker == 2)
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$empid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
}
}
}
}
ini_set('max_execution_time', 999999);
}
}
echo"</table></div>";
/*absentees*/
if($wala == 1)
{
$count = 0;
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
$day = mysqli_query($connect,"select * from nightshiftlist where shift ='dayshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$id = $empinfo['empid'];
$shift = $empinfo['shift'];
$lname = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$date = $empinfo['datefrom'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
for($x = 0; $x<$counterless;$x++)
{
$dempid = $_SESSION['testname'][$x];
if($id == $dempid)
{
$present = 1;
break;
}
else
{
$present = 0;
}
ini_set('max_execution_time', 999999);
}
if($present == 0)
{
echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
ini_set('max_execution_time', 999999);
$count++;
}
}
echo"</table></div>";
echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";
}
}/*end of absentees*/
if($category == 'nightshift')
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('Employee Number','Lastname','Firstname','Department','Section','Time in','Time out','Shift')");
echo "<div class='dayshift'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DATE</th><th>DEPARTMENT</th><th>SECTION</th><th>IN</th><th>OUT</th></tr>";
for($x = 0; $x<$ncounter;$x++)
{
$dempid = $_SESSION['nightname'][$x];
$day = mysqli_query($connect,"select * from nightshiftlist where empid = '$dempid' and shift = 'nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$count++;
if($loop == '1')
{
echo "<td>NO OUT</td></tr>";
$loop=0;
}
$empid = $empinfo['empid'];
$empshift = $empinfo['shift'];
$name = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
$checking = mysqli_query($con,"select * from wawart where Column_1='$empid' and (Column_2 between '$startdate' and '$enddate') order by Column_2 asc");
if($holder == $empinfo['empid'])
{
break;
}
echo"<tr><td>".$empinfo['empid']."</td><td>".$empinfo['lastname']."</td><td>".$empinfo['firstname']."</td><td>".$empinfo['department']."</td><td>".$empinfo['section']."</td>";
if(mysqli_num_rows($checking)>0)
{
while($row=mysqli_fetch_array($checking))
{
$time = $row['Column_3'];
$times = (int)$time;
if($holder == $empinfo['empid'])
{
break;
}
else
{
$inout = $row['Column_4'];
$time = $row['Column_3'];
$dates = $row['Column_2'];
if($loop ==0 && $inout == '1'&& $dates == $startdate)
{
$date = $row['Column_2'];
echo"<td>".$row['Column_2']."</td>";
}
if($loop ==0 && $dates == $startdate)
{
if($inout == '1')
{
$timein = $time;
echo "<td>".$time."</td>";
$loop = 1;
}
if($inout == '4')
{
$timein = 'NO IN';
$loop = 0;
}
}
else
{
if($loop =='1' && $inout == '4')
{
$timeout = $time;
echo "<td>".$time."</td></tr>";
}
if($loop =='1' && $inout == '1')
{
$timeout = 'NO OUT';
echo "<td><B>NO OUT</td></tr>";
}
$loop = 0;
$counter = 0;
$holder = $empinfo['empid'];
$checker = 2;
if($checker == 2)
{
mysqli_query($connect,"insert into forprint (empid,lastname,firstname,department,section,timein,timeout,stat) values('$dempid','$name','$fname','$dept','$section','$timein','$timeout','$empshift')");
if (mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
}
}
}
}
}
ini_set('max_execution_time', 999999);
}
}
echo"</table></div>";
/*absentees*/
if($wala == 1)
{
$count = 0;
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('Employee Number','Lastname','Firstname','Department','Section')");
echo "<div class='absentees'> <table class='CSSTableGenerator'><tr><th>Emp#</th><th>LASTNAME</th><th>FIRSTNAME</th><th>DEPARTMENT</th><th>SECTION</th></tr>";
$day = mysqli_query($connect,"select * from nightshiftlist where shift ='nightshift' and datefrom = '$shiftdate' and datehired <= '$startdate'");
while($empinfo = mysqli_fetch_array($day))
{
$id = $empinfo['empid'];
$shift = $empinfo['shift'];
$lname = $empinfo['lastname'];
$fname = $empinfo['firstname'];
$dept = $empinfo['department'];
$section = $empinfo['section'];
for($x = 0; $x<$ncounter;$x++)
{
$dempid = $_SESSION['nightname'][$x];
if($id == $dempid)
{
$present = 1;
break;
}
else
{
$present = 0;
}
ini_set('max_execution_time', 999999);
}
if($present == 0)
{
echo "<tr><td>".$id."</td><td>".$lname."</td><td>".$fname."</td><td>".$dept."</td><td>".$section."</td></tr>";
mysqli_query($connect,"insert into absentforprint (empid,lastname,firstname,department,section) values ('$id','$lname','$fname','$dept','$section')");
$count++;
}
ini_set('max_execution_time', 999999);
}
echo"</table></div>";
echo"<label class='totalabs'>Total Number of Absentees ".$count."</label>";
}
}/*end of absentees*/
}
?>
The first sql select query you are executing needs to be corrected.Your select sql query does not considering end date. Try the below query
$result = mysqli_query($con,"select * from wawart where Column_2 >= '$startdate' and Column_2 <= '$enddate' order by Column_2 asc");
i have a module which executes two functions. the first filters and showsthe latest comments per category. the second one filters and shows the top commenters of all categories. i want to hack it in order to show the top commenters per category. for the first one there is in the backend the option to select category but for the top commenters there is not.
here is the code of the module. forgive me for its length.
class modK2CommentsHelper
{
public static function getLatestComments(&$params)
{
$mainframe = JFactory::getApplication();
$limit = $params->get('comments_limit', '5');
$user = JFactory::getUser();
$aid = $user->get('aid');
$db = JFactory::getDBO();
$cid = $params->get('category_id', NULL);
$jnow = JFactory::getDate();
$now = K2_JVERSION != '15' ? $jnow->toSql() : $jnow->toMySQL();
$nullDate = $db->getNullDate();
$model = K2Model::getInstance('Item', 'K2Model');
$componentParams = JComponentHelper::getParams('com_k2');
$query = "SELECT c.*, i.catid, i.title, i.alias, category.alias as catalias, category.name as categoryname
FROM #__k2_comments as c
LEFT JOIN #__k2_items as i ON i.id=c.itemID
LEFT JOIN #__k2_categories as category ON category.id=i.catid
WHERE i.published=1
AND ( i.publish_up = ".$db->Quote($nullDate)." OR i.publish_up <= ".$db->Quote($now)." )
AND ( i.publish_down = ".$db->Quote($nullDate)." OR i.publish_down >= ".$db->Quote($now)." )
AND i.trash=0 ";
if (K2_JVERSION != '15')
{
$query .= " AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
}
else
{
$query .= " AND i.access<={$aid} ";
}
$query .= " AND category.published=1 AND category.trash=0 ";
if (K2_JVERSION != '15')
{
$query .= " AND category.access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
}
else
{
$query .= " AND category.access<={$aid} ";
}
$query .= " AND c.published=1 ";
if ($params->get('catfilter'))
{
if (!is_null($cid))
{
if (is_array($cid))
{
JArrayHelper::toInteger($cid);
$query .= " AND i.catid IN(".implode(',', $cid).")";
}
else
{
$query .= " AND i.catid=".(int)$cid;
}
}
}
if (K2_JVERSION != '15')
{
if ($mainframe->getLanguageFilter())
{
$languageTag = JFactory::getLanguage()->getTag();
$query .= " AND category.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") AND i.language IN (".$db->Quote($languageTag).", ".$db->Quote('*').")";
}
}
$query .= " ORDER BY c.commentDate DESC ";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "#\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\#)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\#&=+$,%#-]+)*/?)#";
if (count($rows))
{
foreach ($rows as $row)
{
if ($params->get('commentDateFormat') == 'relative')
{
$config = JFactory::getConfig();
$now = new JDate();
if (K2_JVERSION == '30')
{
$tzoffset = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
$now->setTimezone($tzoffset);
}
else
{
$tzoffset = $config->getValue('config.offset');
$now->setOffset($tzoffset);
}
$created = new JDate($row->commentDate);
$diff = $now->toUnix() - $created->toUnix();
$dayDiff = floor($diff / 86400);
if ($dayDiff == 0)
{
if ($diff < 5)
{
$row->commentDate = JText::_('K2_JUST_NOW');
}
elseif ($diff < 60)
{
$row->commentDate = $diff.' '.JText::_('K2_SECONDS_AGO');
}
elseif ($diff < 120)
{
$row->commentDate = JText::_('K2_1_MINUTE_AGO');
}
elseif ($diff < 3600)
{
$row->commentDate = floor($diff / 60).' '.JText::_('K2_MINUTES_AGO');
}
elseif ($diff < 7200)
{
$row->commentDate = JText::_('K2_1_HOUR_AGO');
}
elseif ($diff < 86400)
{
$row->commentDate = floor($diff / 3600).' '.JText::_('K2_HOURS_AGO');
}
}
}
$row->commentText = K2HelperUtilities::wordLimit($row->commentText, $params->get('comments_word_limit'));
$row->commentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\0">\0</a>', $row->commentText);
$row->itemLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($row->itemID.':'.urlencode($row->alias), $row->catid.':'.urlencode($row->catalias))));
$row->link = $row->itemLink."#comment{$row->id}";
$row->catLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($row->catid.':'.urlencode($row->catalias))));
if ($row->userID > 0)
{
$row->userLink = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
$getExistingUser = JFactory::getUser($row->userID);
$row->userUsername = $getExistingUser->username;
}
else
{
$row->userUsername = $row->userName;
}
// Switch between commenter name and username
if ($params->get('commenterName', 1) == 2)
$row->userName = $row->userUsername;
$row->userImage = '';
if ($params->get('commentAvatar'))
{
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
$comments[] = $row;
}
return $comments;
}
}
public static function getTopCommenters(&$params)
{
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'tables');
$limit = $params->get('commenters_limit', '5');
$user = JFactory::getUser();
$aid = $user->get('aid');
$db = JFactory::getDBO();
$query = "SELECT COUNT(id) as counter, userName, userID, commentEmail FROM #__k2_comments WHERE userID > 0 AND published = 1 GROUP BY userID ORDER BY counter DESC";
$db->setQuery($query, 0, $limit);
$rows = $db->loadObjectList();
$pattern = "#\b(https?://)?(([0-9a-zA-Z_!~*'().&=+$%-]+:)?[0-9a-zA-Z_!~*'().&=+$%-]+\#)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+\.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z]\.[a-zA-Z]{2,6})(:[0-9]{1,4})?((/[0-9a-zA-Z_!~*'().;?:\#&=+$,%#-]+)*/?)#";
$model = K2Model::getInstance('Item', 'K2Model');
$componentParams = JComponentHelper::getParams('com_k2');
if (count($rows))
{
foreach ($rows as $row)
{
if ($row->counter > 0)
{
$row->link = JRoute::_(K2HelperRoute::getUserRoute($row->userID));
if ($params->get('commenterNameOrUsername', 1) == 2)
{
$getExistingUser = JFactory::getUser($row->userID);
$row->userName = $getExistingUser->username;
}
if ($params->get('commentAvatar'))
{
$row->userImage = K2HelperUtilities::getAvatar($row->userID, $row->commentEmail, $componentParams->get('commenterImgWidth'));
}
if ($params->get('commenterLatestComment'))
{
$query = "SELECT * FROM #__k2_comments WHERE userID = ".(int)$row->userID." AND published = 1 ORDER BY commentDate DESC";
$db->setQuery($query, 0, 1);
$comment = $db->loadObject();
$item = JTable::getInstance('K2Item', 'Table');
$item->load($comment->itemID);
$category = JTable::getInstance('K2Category', 'Table');
$category->load($item->catid);
$row->latestCommentText = $comment->commentText;
$row->latestCommentText = preg_replace($pattern, '<a target="_blank" rel="nofollow" href="\0">\0</a>', $row->latestCommentText);
$row->latestCommentLink = urldecode(JRoute::_(K2HelperRoute::getItemRoute($item->id.':'.urlencode($item->alias), $item->catid.':'.urlencode($category->alias))))."#comment{$comment->id}";
$row->latestCommentDate = $comment->commentDate;
}
$commenters[] = $row;
}
}
if (isset($commenters))
return $commenters;
}
}
}
every help is appreciated. thank you very much
I have this pagination class which I converted from a normal procedural function to a class since I started learning OOP. In the old procedural way, the function worked fine but I can't get this new class version to display on the screen
class Pagination {
public function __construct() {
}
/**
* This function is called whenever the there are several records to be displayed in the table
* This saves the page extending further down the page creating a long list of results
* when all the results can be spread across multiple pages
*/
public function pagination_one($total_pages, $page, $webpage) {
// Maximum number of links per page. If exceeded, google style pagination is generated
$max_links = 6;
$h=1;
if($page>$max_links) {
$h=(($h+$page)-$max_links);
}
if($page>=1) {
$max_links = $max_links+($page-1);
}
if($max_links>$total_pages) {
$max_links=$total_pages+1;
}
echo '<div class="page_numbers">
<ul>';
if($page>"1") {
echo '<li class="current">First</li>
<li class="current">Prev</li> ';
}
if($total_pages!=1) {
for ($i=$h;$i<$max_links;$i++) {
if($i==$page) {
echo '<li><a class="current">'.$i.'</a></li>';
}
else
{
echo '<li>'.$i.' </li>';
}
}
}
if(($page >="1")&&($page!=$total_pages)) {
echo '<li class="current">Next</li>
<li class="current">Last</li>';
}
echo '</ul> </div>';
}
and elsewhere in another class I want to create a new instance of that class and pass the method in the return along with some parameters
public function paging() {
if($this->getcount != 0) {
$this->paging = new Pagination();
return $this->paging->pagination_one($this->total_pages, $this->page, 'news');
}
}
When I try I var_dump() it comes up as NULL where I expect to see some pagination on the screen.
What have i got to change to be able to display the pagination? Do I have to created some variables in the Pagination class for $total_pages, $page and $webpage and initialise them in the constructor and remove them from the pagination_one method?
You do
return $this->paging->pagination_one...
when you are not returning anything in pagination_one -method, hence null.
I fixed it myself by removing the private variables in the class and changing the constructor.
The class now looks like this
class Pagination {
public function __construct($total_pages, $page, $webpage) {
$this->total_pages = $total_pages;
$this->page = $page;
$this->webpage = $webpage;
}
/**
* This function is called whenever the there are several records to be displayed in the table
* This saves the page extending further down the page creating a long list of results
* when all the results can be spread across multiple pages
*/
public function pagination_one() {
// Maximum number of links per page. If exceeded, google style pagination is generated
$max_links = 6;
$h = 1;
if($this->page > $max_links) {
$h=(($h + $this->page) - $max_links);
}
if($this->page >= 1) {
$max_links = $max_links + ($this->page - 1);
}
if($max_links > $this->total_pages) {
$max_links = $this->total_pages + 1;
}
$paging = '';
$paging .= '<div class="page_numbers">
<ul>';
if($this->page > "1") {
$paging .= '<li class="current">First</li>
<li class="current">Prev</li> ';
}
if($this->total_pages != 1) {
for ($i=$h; $i < $max_links; $i++) {
if($i == $this->page) {
$paging .= '<li><a class="current">'.$i.'</a></li>';
}
else {
$paging .= '<li>'.$i.' </li>';
}
}
}
if(($this->page >= "1" ) && ($this->page != $this->total_pages)) {
$paging .= '<li class="current">Next</li>
<li class="current">Last</li>';
}
$paging .= '</ul> </div>';
return $paging;
}
}
function pagination($sql_total_row, $post_per_page,$current_page=1, $url='', $lasturl = '', $parameter ='paging') {
$number_page = ceil($sql_total_row / $post_per_page);if($number_page<=1) return false;
$uls ='<ul class="pagination pagination-sm">';
$a = parse_url($url);
if(isset($a['query']))$url .= '&';else $url .= '?';
$url .= $parameter.'=';
$urls = '';
$distanc = 5;
$f = $current_page-$distanc;
$l = $current_page+$distanc;
$li = function($n,$link,$current_page){ return $current_page==$n ? '<li class="active"><span>'.$n.'</span><li>' : '<li>'.$n.'</li>'; };
for ($i = $current_page; $i > 0; $i--){
if($i>$f or $i < $distanc)
$urls = $li($i,$url.$i.$lasturl,$current_page). $urls;
else{
$i = $distanc;
$urls = '<li><span>...</span><li>'.$urls;
}
}
for ($i = $current_page+1; $i < $number_page; $i++){
if($i<$l or $i > $number_page - $distanc)
$urls .= $li($i,$url.$i.$lasturl,$current_page);
else{
$i = $number_page - $distanc;
$urls.= '<li><span>...</span><li>';
}
}
return $uls.$urls.'</ul>';
}
usage:
$total_row_sql = 1500; //required - get from mysql: SELECT FOUND_ROWS();
$row_display = 50; //required
$parameter_paged = (isset($_GET['paging'])) ? $_GET['paging'] : 1; // required
$custom_url = '/wordpress_url/?'; //custom
$hash = '#target_element_id'; //custom
$name_paramerter_paging = 'paging'; //custom
echo pagination($total_row_sql,$row_display,$parameter_paged,$custom_url,$hash,$name_paramerter_paging);
Result:
view result using pagination
========================================================================
Example if using loop from database:
function select( $table, $field='*', $where='', $order='') {
$sql = "select SQL_CALC_FOUND_ROWS $field from $table";
if($where) $sql.= " where $where";
if($order) $sql.= " order by $order";
$items = $wordpress_mysql->get_results( $sql );// custom: default result object, if u want parse array: ( $sql, ARRAY_A);
$sql_posts_total = $wordpress_mysql->get_var( "SELECT FOUND_ROWS();" );
return (object)['result'=>$items, 'total_rows'=>$sql_posts_total];
}
$result = select('user');
$data_items = $result->result;// foreach show database if u want
$sql_posts_total = $result->total_rows;
$post_per_page = 50;
$parameter_paged = (isset($_GET['paging'])) ? $_GET['paging'] : 1;
echo pagination($sql_posts_total,$post_per_page,$parameter_paged);
I have been installing a Wordpress Theme, the theme has a custom navigation function.
It shows a page navigation at archive, categories but doesn't show at tag.
This is the function from functions.php
<?php function wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
global $request, $posts_per_page, $wpdb, $paged;
if(empty($prelabel)) { $prelabel = '<strong>«</strong>';
} if(empty($nxtlabel)) {
$nxtlabel = '<strong>»</strong>';
} $half_pages_to_show = round($pages_to_show/2);
if (!is_single()) {
if(!is_category()) {
preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches); } else {
preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); }
$fromwhere = $matches[1];
$numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere");
$max_page = ceil($numposts /$posts_per_page);
if(empty($paged)) {
$paged = 1;
}
if($max_page > 1 || $always_show) {
echo "$before <div class='Nav'><span>Pages ($max_page): </span>"; if ($paged >= ($pages_to_show-1)) {
echo '« First ... '; }
previous_posts_link($prelabel);
for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) { if ($i >= 1 && $i <= $max_page) { if($i == $paged) {
echo "<strong class='on'>$i</strong>";
} else {
echo ' '.$i.' '; }
}
}
next_posts_link($nxtlabel, $max_page);
if (($paged+$half_pages_to_show) < ($max_page)) {
echo ' ... Last »'; }
echo "</div> $after";
}
}
}
?>
I hope anyone helping with that function to show page navigation at tag, thanks.
It's doing the wrong match. Change if(!is_category()) into if(!is_category()&&!is_tag())
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'