Wpis z mikrobloga

#mysql #pytaniedoeksperta

Jak w tym syf zrobić by pokazywało więcej niż od 01.01.2021

function setTime(){
global $year, $month;
if (isset($_GET['m']) && $_GET['m']<=1 && $_GET['m']>=-19){
$month = $month + $_GET['m'];
if ($month>12){
$month -= 12;
$year++;
} else if ($month<1){
$month += 12;
$year--;
}
}
}

function results(){
global $connection, $month, $year;

$now = getdate();
$month = $now['mon'];
$year = $now['year'];

if (isset($_GET['m']) && $_GET['m']<=1 && $_GET['m']>=-19){
$month = $month + $_GET['m'];
if ($month>12){
$month -= 12;
$year++;
} else if ($month<1){
$month += 12;
$year--;
}
}

$prevmonth = $month-1;
$nextyear = $prevyear = $year;
if ($prevmonth<1) {
$prevmonth = 12;
$prevyear--;
}

$nextmonth = $month+1;
if ($nextmonth>12){
$nextmonth = 1;
$nextyear++;
}

$par = $_GET['m'];
if (!isset($par)){
$parprev = -1;
$parnext = 1;
} else {
$parprev = $par - 1;
$parnext = $par + 1;
}
echo "|";
if ($_GET['m']>-19 && $_GET['m']<=1 || !isset($_GET['m'])) {
echo " < $prevmonth.$prevyear |";
} else {
echo " |";
}
echo " **$month.$year** |";
if ($_GET['m']<1 && $_GET['m'] >=-19 || !isset($_GET['m'])) {
echo " $nextmonth.$nextyear > |";
} else {
echo " |";
}
echo "
";

$asortQuery = "select id,name from sale_assortment where active=1";
$resAsort = mysql_query($asortQuery, $connection);
$asortRows = mysql_num_rows($resAsort);
for ($i=0; $i<$asortRows; $i++){
$asortData = mysql_fetch_row($resAsort);
$assortment[$i] = array($asortData[0],$asortData[1]);
}

$query = "select c.name,sum(a.dayturnover),b.turnover,sum(a.dayenters),sum(a.daybills),b.efficiency,b.enters,b.workdays,count(a.id),c.id,b.asort1,b.asort2,b.asort3,b.asort4,b.asort5,b.asort6,sum(a.asort1),sum(a.asort2),sum(a.asort3),sum(a.asort4),sum(a.asort5),sum(a.asort6)
from sale_saloon_data as a, sale_planned_values as b, sale_users as c
where c.id=a.user_id and c.id=b.user_id and c.id!=$_SESSION[userId] and a.year=$year and a.month=$month and b.month=$month and b.year=$year";
if (isRegion()){
$query .= " and c.parent_id=".$_SESSION['userId'];
}
$query .= " group by c.id";
$res = mysql_query($query, $connection);
$rows = mysql_num_rows($res);

$rozpych = "![](1x1.gif)
";

if ($_GET['dir'] == 'desc') $dir = 'asc'; else $dir = 'desc';
  • 7
if (isset($GET['m']) && $GET['m']<=1 && $_GET['m']>=-19)


@airflame: Daj mniej niż -19, to będziesz mógł przesunąć się dalej w przeszłość; albo zrób normalnie, na wejściu miesiąc i rok i tyle
@airflame: Bo to tak działa. Przesuwasz się o określoną liczbę miesięcy w tył. Maksymalnie 18. Jeśli chcesz dalej, to albo daj większy limit np. wszystkie -19 zamień na -49, albo przerób tak, żeby na wejściu brało rok i miesiąc, które chcesz wyświetlić.
@januzi:
Usmarkaliśmy z kolegą w tym smarku coś takiego i działa.

function setTime(){
global $year, $month;
if (isset($_GET['m']) && $_GET['m']<=1 && $_GET['m']>=-($latwstecz*12+$month)){
$month = $month + $_GET['m'] ;
if ($month>12){
$month -= 12;
$year++;
} else if ($month<1){
$month += 12;
$year--;
//pętla na kolejne lata wstecz
while ($month<1){
$month += 12;
$year--;
}
}
}
}

function results(){
global $connection, $month, $year;

$now = getdate();
$month = $now['mon'];
$year =
@airflame: Jeszcze tak dla pewności wyświetl sobie to, co siedzi w $query. Następnie otwórz phpmyadmina, wybierz odpowiednią bazę, wejdź w zakładkę sql i wklej to zapytanie. Następnie dopisz na samym początku "explain" i każ mysqlowi pokazać wynik. Jeśli jest gdzieś ALL i duża liczba rekordów, to warto poprawić także strukturę tabel.