PHP GET Today Yesterday Last-7-Days This-Month-Last-Month This-Year Last-Year,All-Time

PHP GET Today Yesterday Last-7-Days This-Month-Last-Month This-Year Last-Year,All-Time

Welcome to the In Pakainfo.com website! You will Step By Step learn web programming, easy and very fun. This website allmost provides you with a complete web programming tutorial presented in an easy-to-follow manner. Each web programming tutorial has all the practical examples with web programming script and screenshots available.For

Select records from today, this week, this month php mysql

<?php 
echo "<pre>";
echo $today = date('Y-m-d');
echo $datseven=date('Y-m-d', strtotime('-7 days'));
echo $datyesterday=date('Y-m-d', strtotime('-1 days'));
echo $thismonth=date('m');
echo $lastmonth=date('m', strtotime(date('Y-m')." -1 month"));
echo $thisyear=date('Y');
echo $lastyear=date("Y",strtotime("-1 year"));
echo "</pre>";
?>

HTML Part

<div class="col-md-6 col-md-offset-1 col-sm-6 col-xs-12">
	<div class="select_box">
		<select id="selectidbigmachine">
			<option value="0" name="0">Today</option>
			<option value="1" name="1">Yesterday</option>
			<option value="7" name="7">Last 7 Days</option>
			<option value="30" name="30">This Month</option>
			<option value="31" name="31">Last Month</option>
			<option value="365" name="365">This Year</option>
			<option value="366" name="366">Last Year</option>
			<option value="9" name="9">All Time</option>
		</select>
	</div>
</div>

php Part : Query check function

<?php
function getfilterdata($sdate)
{

/*Filter Date Logic*/
$today = date('Y-m-d');
$datseven=date('Y-m-d', strtotime('-7 days'));
$datyesterday=date('Y-m-d', strtotime('-1 days'));
$thismonth=date('m');
$lastmonth=date('m', strtotime(date('Y-m')." -1 month"));
$thisyear=date('Y');
$lastyear=date("Y",strtotime("-1 year"));
			
if($sdate==7)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where DATE(subbig.date) >= '$datseven' and DATE(suptotal.sdate) >= '$datseven' ORDER BY users.name ASC";
		}
		if($sdate==1)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where DATE(subbig.date) = '$datyesterday' and DATE(suptotal.sdate) = '$datyesterday' ORDER BY users.name ASC";
				 
		}
		if($sdate==30)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where MONTH(subbig.date) = '$thismonth' and MONTH(suptotal.sdate) = '$thismonth' ORDER BY users.name ASC";
				
		}
		if($sdate==31)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where MONTH(subbig.date) = '$lastmonth' and MONTH(suptotal.sdate) ='$lastmonth' ORDER BY users.name ASC";
				
		}
		if($sdate==365)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where YEAR(subbig.date) = '$thisyear' and YEAR(suptotal.sdate) ='$thisyear' ORDER BY users.name ASC";
				
		}
		if($sdate==366)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where YEAR(subbig.date) = '$lastyear' and YEAR(suptotal.sdate) ='$lastyear' ORDER BY users.name ASC";
				
		}
		if($sdate==0)
		{
				$query = "select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id 
				INNER JOIN suptotal ON users.id=suptotal.user_id where DATE(subbig.date) = '$today' and DATE(suptotal.sdate) = '$today' ORDER BY users.name ASC";
		}
		if($sdate==9)
		{
				$query = "select DISTINCT (users.id),SUM(suptotal.total) as total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id 
				INNER JOIN suptotal ON users.id=suptotal.user_id GROUP BY users.id ORDER BY users.name ASC";
		}
		echo "<pre>";
		print_r($query);
		echo "</pre>";
}
?>

Join Query with Date Format Yesterday

Also Read :  How to get current url with or without query string using Vuejs

$query = “select DISTINCT (users.id),suptotal.total,users.user_bm_percent,users.user_type,users.name,users.user_on_percent,users.status from users INNER JOIN subbig ON users.id=subbig.user_id INNER JOIN suptotal ON users.id=suptotal.user_id where DATE(subbig.date) = ‘$datyesterday’ and DATE(suptotal.sdate) = ‘$datyesterday’ ORDER BY users.name ASC”;

Example

Recommended For You.

PHP Multiple Checkbox Array Handling Tutorial Example
Today, We want to share with you PHP Multiple Checkbox Array Handling Tutorial Example.In this post we will show you

Add a Comment

Your email address will not be published. Required fields are marked *