<a href="https://console.cloud.google.com/apis/credentials">Get Your Api Credentials Here</a> <a href="https://calendar.google.com/calendar">Get your Calender ID</a> <?php include_once("wp-load.php"); function get_calender_events() { $params = array(); /*Get current date*/ $current_date = date('Y-m-d H:i:s'); /*Convert it to google calendar's rfc_format */ $rfc_format = date("c", strtotime($current_date)); $params[] = 'orderBy=startTime'; $params[] ='maxResults=100'; $params[] = 'timeMin='.urlencode($rfc_format); $url_param = ''; foreach($params as $param) { $url_param.= '&'.$param; } $calender_id = "calender_id"; $client_key = "client_key"; $url = "https://www.googleapis.com/calendar/v3/calendars/".$calender_id."/events?key=".$client_key."&singleEvents=true".$url_param; $list_events = wp_remote_post($url, ...
Smarty Pagination with php mysql
-------------------------------------------------------------
--------------------------------------------------------------
<?php
Pagination using PHP,Smarty And MySql
$sql="SELECT * FROM `fieldname1` WHERE is_active='Y' ORDER BY fieldmame2";
$rs=mysql_query($sql);
$num=mysql_num_rows($rs);
$i=0;
/*while ($row = mysql_fetch_array($rs)) {
$arr1[$j] = $row;
$j++;
}*/
////////////////////////////////////////////
if (!(isset($pagenum)))
{
$pagenum = 1;
}
//Here we count the number of results
//Edit $data to be your query
$rows = $num;
//This is the number of results displayed per page
$page_rows = 2;
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$SqlQuery=$sql." LIMIT ". ($pagenum - 1) * $page_rows.",$page_rows";
$data_p=mysql_query($SqlQuery);
////////////////////////////////////////////
while($row1 = mysql_fetch_array($data_p)) {
$arr[$i] = $row1;
$i++;
}
if ($pagenum == 1)
{
}
else
{
$previous = $pagenum-1;
}
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
}
$smarty->assign("arr",$arr);
$smarty->assign("pagenum",$pagenum);
$smarty->assign("previous",$previous);
$smarty->assign("last",$last);
$smarty->assign("next",$next);
?>
-------------------------------------------------------
-------------------------------------------------------
Example:
////////////
//search.php
////////////
function get_db_results()
{
$id = $_GET['id'];
if (preg_match('#[^A-Za-z0-9]#', $id)) {
echo "<center><font style=\"font-family:tahoma;\">...should be between 4 and 40 letters and numbers only. <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
if (strlen($id) < 4) {
echo "<center><font style=\"font-family:tahoma;\">Field must be at least 4 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
if (strlen($id) > 40) {
echo "<center><font style=\"font-family:tahoma;\">Field Max Characters: 40
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM links WHERE linkname LIKE '%%$id%%' LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$_result = mysql_query($_query);
while ($_row = mysql_fetch_array($_result, MYSQL_ASSOC)) {
$_data[] = $_row;
}
$_query = "SELECT FOUND_ROWS() as total";
$_result = mysql_query($_query);
$_row = mysql_fetch_array($_result, MYSQL_ASSOC);
SmartyPaginate::setTotal($_row['total']);
mysql_free_result($_result);
return @$_data;
}
require ('libs/SmartyPaginate.class.php');
SmartyPaginate::connect();
SmartyPaginate::setLimit(10);
SmartyPaginate::setUrl('search.php');
$smarty->assign('results', get_db_results());
SmartyPaginate::assign($smarty);
$smarty->display('search.php');
//////////////////////
//search.php(template)
//////////////////////
{section name="results" loop=$results}
{$results[results].linkname}<br />
{/section}
Links {$paginate.first}-{$paginate.last} of {$paginate.total}.
{paginate_prev} {paginate_next}
-------------------------------------------------------------
--------------------------------------------------------------
<?php
Pagination using PHP,Smarty And MySql
$sql="SELECT * FROM `fieldname1` WHERE is_active='Y' ORDER BY fieldmame2";
$rs=mysql_query($sql);
$num=mysql_num_rows($rs);
$i=0;
/*while ($row = mysql_fetch_array($rs)) {
$arr1[$j] = $row;
$j++;
}*/
////////////////////////////////////////////
if (!(isset($pagenum)))
{
$pagenum = 1;
}
//Here we count the number of results
//Edit $data to be your query
$rows = $num;
//This is the number of results displayed per page
$page_rows = 2;
//This tells us the page number of our last page
$last = ceil($rows/$page_rows);
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$SqlQuery=$sql." LIMIT ". ($pagenum - 1) * $page_rows.",$page_rows";
$data_p=mysql_query($SqlQuery);
////////////////////////////////////////////
while($row1 = mysql_fetch_array($data_p)) {
$arr[$i] = $row1;
$i++;
}
if ($pagenum == 1)
{
}
else
{
$previous = $pagenum-1;
}
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
}
$smarty->assign("arr",$arr);
$smarty->assign("pagenum",$pagenum);
$smarty->assign("previous",$previous);
$smarty->assign("last",$last);
$smarty->assign("next",$next);
?>
-------------------------------------------------------
-------------------------------------------------------
Example:
////////////
//search.php
////////////
function get_db_results()
{
$id = $_GET['id'];
if (preg_match('#[^A-Za-z0-9]#', $id)) {
echo "<center><font style=\"font-family:tahoma;\">...should be between 4 and 40 letters and numbers only. <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
if (strlen($id) < 4) {
echo "<center><font style=\"font-family:tahoma;\">Field must be at least 4 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
if (strlen($id) > 40) {
echo "<center><font style=\"font-family:tahoma;\">Field Max Characters: 40
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
die();
}
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM links WHERE linkname LIKE '%%$id%%' LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$_result = mysql_query($_query);
while ($_row = mysql_fetch_array($_result, MYSQL_ASSOC)) {
$_data[] = $_row;
}
$_query = "SELECT FOUND_ROWS() as total";
$_result = mysql_query($_query);
$_row = mysql_fetch_array($_result, MYSQL_ASSOC);
SmartyPaginate::setTotal($_row['total']);
mysql_free_result($_result);
return @$_data;
}
require ('libs/SmartyPaginate.class.php');
SmartyPaginate::connect();
SmartyPaginate::setLimit(10);
SmartyPaginate::setUrl('search.php');
$smarty->assign('results', get_db_results());
SmartyPaginate::assign($smarty);
$smarty->display('search.php');
//////////////////////
//search.php(template)
//////////////////////
{section name="results" loop=$results}
{$results[results].linkname}<br />
{/section}
Links {$paginate.first}-{$paginate.last} of {$paginate.total}.
{paginate_prev} {paginate_next}
Comments
Post a Comment