Guys we have a website that records the travel time of the vehicle. We have different kinds of reports. The problem is that our 2 reports is not the same on the last data. I think our problem is on the syntax on the display of our report.
here are sample screenshots of our reports. the KMLOG and the Daily Report. our problem is we need to display the output of the
]
if($endidling){
$total_idling=xtimediff($s_idling_date." ".$s_idling_time,$e_idling_date." ".$e_idling_time);
//if ($total_idling>=($entry['ilimit']*60)){
if($s_idling_date==$e_idling_date){
$data[$myCount]["xtype"] = "idling";
$data[$myCount]["dur"] = sec2hms($total_idling);
$data[$myCount]["sdate"] =date('M d',strtotime($s_idling_date));
$data[$myCount]["stime"] =$s_idling_time." to ".$e_idling_time;
$data[$myCount]["location"] = $location;
$myCount +=1;
}
else{
//$data[$myCount]["stime"] =$s_idling_time." to ".$e_idling_time." of ".date('M d',strtotime($e_idling_date)) ;
$day_def=def_date($s_idling_date,$e_idling_date);
for($day=0;$day<=$day_def;$day++){
if($day==0){
$ddur = xtimediff($s_idling_date." ".$s_idling_time,$s_idling_date." ".$gabi);
$data[$myCount]["stime"] =$s_idling_time." to ".$gabi;
$next_day=$s_idling_date;
}
elseif($day==$day_def){
$ddur = xtimediff($e_idling_date." ".$umaga,$e_idling_date." ".$e_idling_time);
$data[$myCount]["stime"] =$umaga." to ".$e_idling_time;
$next_day = date('Y-m-d', strtotime($next_day . ' +1 day'));
}
else{
$ddur = xtimediff($s_idling_date." ".$umaga,$s_idling_date." ".$gabi);
$data[$myCount]["stime"] =$umaga." to ".$gabi;
$next_day = date('Y-m-d', strtotime($next_day . ' +1 day'));
}
//if($day==0) $ddur= xtimediff($s_off_date." ".$s_off_time,$e_off_date." ".$e_off_time);
$data[$myCount]["xtype"] = "idling";
$data[$myCount]["dur"] = sec2hms($ddur);
$data[$myCount]["sdate"] =date('M d',strtotime($next_day));
$data[$myCount]["location"] = $location;
$myCount +=1;
}
}
//}
$endidling=false;
$total_idling=0;
}
Related
I am making a simple visitor counter without MySQL in a WordPress plugin. To achieve this I make a simple text visitor.db where store visitor ip for a while and show the total number of IPs as current online visitor and after a time period the history log delete. But now I want to implement from that visitor.db to save them another.db where it count total visitor till today. Is it possible?
If I count while loop ? how can I save it to another.db
$counter = 0;
while(..) {
$counter++;
}
echo $counter;
For example now it show Online : 70
But I want to achieve Total : 145875458 Online : 70 something like this
define('VISITOR_DATA_PATH',plugin_dir_path( __FILE__ ));
$dbfile = VISITOR_DATA_PATH . "visitors.db";
$expire = 300; // average time in seconds to consider someone online before removing from the list
if(!file_exists($dbfile)) {
die("Error: Data file " . $dbfile . " NOT FOUND!");
}
if(!is_writable($dbfile)) {
die("Error: Data file " . $dbfile . " is NOT writable! Please CHMOD it to 666!");
}
function getIPs() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif(isset($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];
else $ip = "0";
return $ip;
}
function CountVisitors() {
global $dbfile, $expire;
$cur_ip = getIPs();
$cur_time = time();
$dbary_new = array();
$dbary = unserialize(file_get_contents($dbfile));
if(is_array($dbary)) {
while(list($user_ip, $user_time) = each($dbary)) {
if(($user_ip != $cur_ip) && (($user_time + $expire) > $cur_time)) {
$dbary_new[$user_ip] = $user_time;
}
}
}
$dbary_new[$cur_ip] = $cur_time; // add record for current user
$fp = fopen($dbfile, "w");
fputs($fp, serialize($dbary_new));
fclose($fp);
$out = sprintf("%3d", count($dbary_new)); // format the result to display 3 digits with leading 0's
return $out;
}
function visitor_counter_shrocode(){
$visitors_online = CountVisitors();
ob_start();
$output='<span> Online: <b>'.$visitors_online.'</b></span>';
ob_end_clean();
return $output;
}
add_shortcode('onlinevisitor','visitor_counter_shrocode');
Bit of an odd one and not even sure this is possible or if there is a better way to do it.
Basically, I have a "job package" that holds various bits of data. The main one is something called CV Credits - the user has to buy "CV Credits" to view a cv. Once out of CV Credits they have to buy more. The more complicated thing is that they can have many different packages at the same time.
So my logic was to check each package , check the first and use up the credits there first, then the second and so on. If none, they have to buy - with me?
Ok so here is my code (which only gathers the information from the first package) it is perfect, but how do I adapt the code to check the second when the variable $how_many_left is = "0"
php
$first = true;
foreach ( $packages as $package ) {
if ( $first ) {
$package = wc_paid_listings_get_package( $package );
$package_id = $package->get_id();
$cv_credit = $wpdb->get_row( "SELECT cv_credit, cv_credit_count, cv_credit_duration, date_purchased, credit_value FROM `wp_wcpl_user_packages` WHERE id = $package_id" );
$amount_of_credits = $cv_credit->cv_credit; // AMOUNT OF CREDITS THE PACKAGE HAS
$how_many_used = $cv_credit->cv_credit_count; // THE AMOUNT THEY HAVE USED
$credit_value = $cv_credit->credit_value; // WHAT THEY HAVE SEEN (COMMA SEPARATED)
$how_many_left = $amount_of_credits - $how_many_used;
$credit_duration = $cv_credit->cv_credit_duration;
$date_purchased = $cv_credit->date_purchased;
$timestamp = strtotime($date_purchased);
$date_purchased_yday = date("d", $timestamp); // day of the year
$dayend = $date_purchased_yday + $credit_duration - 1; // when it ends
$today = getdate();
$today_yday = $today["yday"]; // todays day of the year
$timeleft = $dayend - $today_yday;
if ($timeleft >= "0") {
if ($how_many_left >= "1") {
$createarrayofvalues = explode(',', $credit_value);
if (in_array($post->ID, $createarrayofvalues)) {
?>
<div class="contact-information">
<p>Mobile Number: <?php echo $mobile_number; ?> </p>
<p>Email Address: <?php echo $email; ?> </p>
<p>Links:
<?php the_resume_links(); ?>
</p>
</div>
<?php
} // IF they have paid for the CV before
else {
?> View contact information (<?php echo $how_many_left ?> credit/s left) <?php
}
} // how many left
else {
echo "You have no more credits for this package";
}
}// time left on package
else {
}
$first = false;
} // if First
else {
}
}
I then use ajax to update the database with another CV count and other bits of information when they click on the "view contact information" button if they have credits and havent looked at the contact details before.
I do hope I am making sense, please ask any questions as there is information in there that is part of the code but doesnt necessary need to be there for this example.
To confirm: I want to check the first package in the loop - once there are no more credits to use, I then move onto the next package and so on.
Thanks in advance
Basically findPackageWithCredits looks for a package that has credits left or returns null. This could still be made a lot nicer, but maybe it gives you something to start with ;)
<?php
handle($packages);
function handle($packages)
{
global $post;
$package = findPackageWithCredits($packages);
if (null === $package) {
echo "no credits left, buy more!";
return;
}
if (in_array($post->ID, explode(',', $package->credit_value))) {
showContact();
return;
}
showCVInfo($package->cv_credit - $package->cv_credit_count);
}
function findPackageWithCredits($packages)
{
foreach ($packages as $package) {
$db_package = getValidatedDatabasePackage($package);
if (null !== $db_package) {
return $db_package;
}
}
return null;
}
function getValidatedDatabasePackage($package)
{
global $wpdb;
$package = wc_paid_listings_get_package($package);
$package_id = $package->get_id();
$cv_credit = $wpdb->get_row("SELECT cv_credit, cv_credit_count, cv_credit_duration, date_purchased, credit_value FROM `wp_wcpl_user_packages` WHERE id = $package_id");
$amount_of_credits = $cv_credit->cv_credit; // AMOUNT OF CREDITS THE PACKAGE HAS
$how_many_used = $cv_credit->cv_credit_count; // THE AMOUNT THEY HAVE USED
$how_many_left = $amount_of_credits - $how_many_used;
$credit_duration = $cv_credit->cv_credit_duration;
$date_purchased = $cv_credit->date_purchased;
$timestamp = strtotime($date_purchased);
$date_purchased_yday = date("d", $timestamp); // day of the year
$dayend = $date_purchased_yday + $credit_duration - 1; // when it ends
$today = getdate();
$today_yday = $today["yday"]; // todays day of the year
$timeleft = $dayend - $today_yday;
if ($timeleft >= "0" && $how_many_left >= "1") {
return $cv_credit;
}
return null;
}
function showContact()
{
global $mobile, $email, $links;
$message = '<div class="contact-information">
<p>Mobile Number: %s </p>
<p>Email Address: %s </p>
<p>Links: %s
</p>
</div>';
echo sprintf($message, $mobile, $email, $links);
}
function showCVInfo($remaining_credits)
{
$message = 'View contact information (%s credit/s left)';
echo sprintf($message, $remaining_credits);
}
My error message in codeigniter framework:
A Database Error Occurred
Error Number: 1140
In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'hms.rooms.id'; this is incompatible with sql_mode=only_full_group_by
SELECT `rooms`.*, count(room_no) as total_rooms FROM `rooms` WHERE `room_type_id` = '10'
Filename: D:/Installed_Apps/OpenServer/OpenServer/domains/hms.loc/system/database/DB_driver.php
Line Number: 691
Why is there such an error and how to eliminate it? In what there can be a problem in the code?
In these functions, something is wrong or everything is normal?
function check_availability($check_in,$check_out,$adults,$kids,$room_type_id){
$query = '?date_from='.$check_in.'&date_to='.$check_out.'&adults='.$adults.'&kids='.$kids.'&room_type=';
$CI =& get_instance();
if($check_in==$check_out){
$check_out = date('Y-m-d', strtotime($check_out.'+ 1 day'));
}
$CI->db->where('id',1);
$settings = $CI->db->get('settings')->row_array();
$CI->db->where('id',$room_type_id);
$CI->db->select('room_types.*,base_price as price');
$room_type = $CI->db->get('room_types')->row_array();
//echo '<pre>'; print_r($room_type);die;
$CI->db->where('room_type_id',$room_type_id);
$CI->db->select('rooms.*,count(room_no) as total_rooms');
$rooms = $CI->db->get('rooms')->row_array();
$total_rooms = $rooms['total_rooms'];
//echo '<pre>'; print_r($rooms);die;
$begin = new DateTime($check_in);
$end = new DateTime($check_out);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
foreach($period as $dt){
$date = $dt->format( "Y-m-d" );
$dayno = $dt->format( "N" );
$day = $dt->format( "D" );
$day = strtolower($day);
///echo $date;die;
//check for room block period
if($date >= $settings['room_block_start_date'] && $date <=$settings['room_block_end_date'])
{
$block_message = "Sorry.. No Room Available Between ".date('d/m/Y',strtotime($settings['room_block_start_date']))." to ".date('d/m/Y',strtotime($settings['room_block_end_date']))." ";
$CI->session->set_flashdata('error', $block_message);
redirect('');
}
$CI->db->where('O.room_type_id',$room_type_id);
$CI->db->where('R.date',$date);
$CI->db->select('R.*,');
$CI->db->join('orders O', 'O.id = R.order_id', 'LEFT');
$orders = $CI->db->get('rel_orders_prices R')->result_array();
//echo '<pre>'; print_r($orders);die;
//echo $total_rooms;die;
if($total_rooms > 0){
//echo count($orders);die;
if(count($orders) >= $total_rooms){
$CI->session->unset_userdata('booking_data');
$CI->session->unset_userdata('coupon_data');
$CI->session->set_flashdata('error', "Sorry.. This Dates Between Rooms Not Available Please Try With Another Date Or Room");
redirect('front/book/index'.$query);
}else{
continue; // continue loop
}
}else{
$CI->session->unset_userdata('booking_data');
$CI->session->unset_userdata('coupon_data');
$CI->session->set_flashdata('error', "Sorry.. This Dates Between Rooms Not Available Please Try With Another Date Or Room");
redirect('front/book/index'.$query);
}
}
return;
}
function check_availability_ajax($check_in,$check_out,$adults,$kids,$room_type_id){
$query = '?date_from='.$check_in.'&date_to='.$check_out.'&adults='.$adults.'&kids='.$kids.'&room_type=';
$CI =& get_instance();
if($check_in==$check_out){
$check_out = date('Y-m-d', strtotime($check_out.'+ 1 day'));
}
$CI->db->where('id',1);
$settings = $CI->db->get('settings')->row_array();
$CI->db->where('id',$room_type_id);
$CI->db->select('room_types.*,base_price as price');
$room_type = $CI->db->get('room_types')->row_array();
//echo '<pre>'; print_r($room_type);die;
$CI->db->where('room_type_id',$room_type_id);
$CI->db->select('rooms.*,count(room_no) as total_rooms');
$rooms = $CI->db->get('rooms')->row_array();
$total_rooms = $rooms['total_rooms'];
//echo '<pre>'; print_r($rooms);die;
$begin = new DateTime($check_in);
$end = new DateTime($check_out);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
foreach($period as $dt){
$date = $dt->format( "Y-m-d" );
$dayno = $dt->format( "N" );
$day = $dt->format( "D" );
$day = strtolower($day);
if($date >= $settings['room_block_start_date'] && $date <=$settings['room_block_end_date'])
{
$block_message = "Sorry.. No Room Available Between ".date('d/m/Y',strtotime($settings['room_block_start_date']))." to ".date('d/m/Y',strtotime($settings['room_block_end_date']))." ";
return $block_message;
}
$CI->db->where('O.room_type_id',$room_type_id);
$CI->db->where('R.date',$date);
$CI->db->select('R.*,');
$CI->db->join('orders O', 'O.id = R.order_id', 'LEFT');
$orders = $CI->db->get('rel_orders_prices R')->result_array();
//echo $total_rooms;die;
if($total_rooms > 0){
if(count($orders) > $total_rooms){
$CI->session->unset_userdata('booking_data');
$CI->session->unset_userdata('coupon_data');
return 'Sorry.. This Dates Between Rooms Not Available Please Try With Another Date Or Room';
}else{
continue; // continue loop
}
}else{
$CI->session->unset_userdata('booking_data');
$CI->session->unset_userdata('coupon_data');
return 'Sorry.. This Dates Between Rooms Not Available Please Try With Another Date Or Room';
}
}
return 1;
}
Here is my Book.php controller code where I use that functions:
function index()
{
//echo '<pre>'; print_r($_GET);
//check availbilty
//get_invoice_number();
$this->session->unset_userdata('booking_data');
$this->session->unset_userdata('coupon_data');
$data['page_title'] = lang('make_reservation');
$data['meta_description'] = $this->setting->meta_description;
$data['meta_keywords'] = $this->setting->meta_keywords;
$data['banners'] = $this->homepage_model->get_banners();
$data['testimonials'] = $this->homepage_model->get_testimonials(); // get 6 testimonials
$data['room_types'] = $this->homepage_model->get_room_types_all();
$data['taxes'] = $this->homepage_model->get_taxes();
if(!empty($_GET['room_type'])){
$data['services'] = $this->homepage_model->get_paid_services($_GET['room_type']);
}
//echo '<pre>'; print_r($data['services']);
if(empty($_GET['room_type'])){
$this->render('book/room_types', $data);
}else{
check_availability($_GET['date_from'],$_GET['date_to'],$_GET['adults'],$_GET['kids'],$_GET['room_type']);
$data['room_type'] = $this->homepage_model->get_room_type($_GET['room_type']);
$this->render('book/view', $data);
}
}
you are facing this problem because of the ONLY_FULL_GROUP_BY option in the MYSQL so kindly set,
SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',''));
to solve the issue.
SQL query including aggregate functions like COUNT() or SUM() etc. always have a GROUP BY clause in it. Which specifies the other non-grouped columns in the final resultset.
In you query the following remarks are noted:
You have specified rooms.* which is not recommended while grouping.
You may mention specific columns while grouping, and specify those columns in the GROUP BY clause too.
For example,
SELECT
Count(product_tb.product_id),
product_tb.`name`,
product_tb.details
FROM
`product_tb`
WHERE
product_tb.product_id = 1
GROUP BY
product_tb.`name`,
product_tb.details
How to calculate a date before 10 days of every month end ?Am using codeigniter platform.
I need to check whether a date is within 10 days before the end of every month.
Please help
You can try using date_modify function for example see this php documentation
http://php.net/manual/en/datetime.modify.php
i need to check whether a date is within10 days before the end of a month
function testDate($date) {
$uDate = strtotime($date);
return date("m", $uDate) != date("m", strtotime("+10 days", $uDate));
}
echo testDate("2016-03-07") ? "Yes" :"No"; // No
echo testDate("2016-03-27") ? "Yes" :"No"; // Yes
you can create a library with this
class Calculate_days{
function __construct() {
parent::__construct();
}
function calculate( $to_day = date("j") ){
$days_month = date("t");
$result = (int) $days_month - $to_day;
if( $result <= 10){
$result = array("type" => TRUE, "missing" => $result . 'days');
return $result;
}
else{
$result = array("type" => FASLE, "missing" => $result . 'days');
return $result;
}
}
}
controller.php
function do_somthing(){
$this->load->library('Calculate_days');
$result = $this->Calculate_days->calculate(date("j"));
var_dump($result);
}
Trying to setup a page that auto updates based on the users date/time.
Need to run a promotion for 2 weeks and each day it needs to change the displayed image.
Was reading through http://www.thetricky.net/php/Compare%20dates%20with%20PHP to get a better handle on php's time and date functions.Somewhat tricky to test, but I basically got stuck on:
<?php
$dateA = '2012-07-16';
$dateB = '2012-07-17';
if(date() = $dateA){
echo 'todays message';
}
else if(date() = $dateB){
echo 'tomorrows message';
}
?>
I know the above function is wrong as its setup, but I think it explains what I am aiming for.
Time is irrelevant, it needs to switch over at midnight so the date will change anyway.
You seem to need this:
<?php
$dateA = '2012-07-16';
$dateB = '2012-07-17';
if(date('Y-m-d') == $dateA){
echo 'todays message';
} else if(date('Y-m-d') == $dateB){
echo 'tomorrows message';
}
?>
you want
<?php
$today = date('Y-m-d')
if($today == $dateA) {
echo 'todays message';
} else if($today == $dateB) {
echo 'tomorrows message';
}
?>
I would go a step back and handle it via file names. Something like:
<img src=/path/to/your/images/img-YYYY-MM-DD.jpg alt="alternative text">
So your script would look something like this:
<img src=/path/to/your/images/img-<?php echo date('Y-m-d', time()); ?>.jpg alt="alternative text">
If you're going to do date calculations, I'd recommend using PHP's DateTime class:
$promotion_starts = "2012-07-16"; // When the promotion starts
// An array of images that you want to display, 0 = the first day, 1 = the second day
$images = array(
0 => 'img_1_start.png',
1 => 'the_second_image.jpg'
);
$tz = new DateTimeZone('America/New_York');
// The current date, without any time values
$now = new DateTime( "now", $tz);
$now->setTime( 0, 0, 0);
$start = new DateTime( $promotion_starts, $tz);
$interval = new DateInterval( 'P1D'); // 1 day interval
$period = new DatePeriod( $start, $interval, 14); // 2 weeks
foreach( $period as $i => $date) {
if( $date->diff( $now)->format("%d") == 0) {
echo "Today I should display a message for " . $date->format('Y-m-d') . " ($i)\n";
echo "I would have displayed: " . $images[$i] . "\n"; // echo <img> tag
break;
}
}
Given that the promotion starts on 07-16, this displays the following, since it is now the second day of the promotion:
Today I should display a message for 2012-07-17 (1)
I would have displayed: the_second_image.jpg