Pereiti prie turinio

Rekomenduojami pranešimai

Sveiki, gal galit kas padėt arba užvest ant kelio. Kaip padaryt kad paspaudus linką rodytų kito mėnesio kalendorių? Mėginau su GET daryt, bet nelabai gavosi. Tikriausiai šiuo atveju tik PHP neužtenka?

 

Čia neparašiau savo varianto nes labai kvailas kodas manyčiau.

<?php
$month = date('m');
$year = date('Y');

$first_day_timestamp = mktime(0,0,0,$month,1,$year); 
$maxday = date("t",$first_day_timestamp); 
$thismonth = getdate($first_day_timestamp); 
$startday = $thismonth['wday']-1;
if($startday < 0 ) $startday = 6; 

echo '<table>';
for ($i=0; $i<($maxday+$startday); $i++) {
       if (($i % 7) == 0 ) echo "<tr>";
       if ($i < $startday) { echo "<td> </td>"; continue; };
       $current_day = $i - $startday + 1;
       if ($current_day<10) $current_day = '0'.$current_day;
       echo "<td>". $current_day . "</td>";
       if (($i % 7) == 6 ) echo "</tr>";
}
echo '</table>';
?>

Redagavo Zimex
Nuoroda į pranešimą
Dalintis kituose puslapiuose

Kažkas tokio

<?php
$month = isset($_GET['m']) ? $_GET['m'] : date('m');
$year = isset($_GET['y']) ? $_GET['y'] : date('Y');

$first_day_timestamp = mktime(0,0,0,$month,1,$year); 
$maxday = date("t",$first_day_timestamp); 
$thismonth = getdate($first_day_timestamp); 
$startday = $thismonth['wday']-1;
if($startday < 0 ) $startday = 6; 

echo '<table>';
for ($i=0; $i<($maxday+$startday); $i++) {
       if (($i % 7) == 0 ) echo "<tr>";
       if ($i < $startday) { echo "<td> </td>"; continue; };
       $current_day = $i - $startday + 1;
       if ($current_day<10) $current_day = '0'.$current_day;
       echo "<td>". $current_day . "</td>";
       if (($i % 7) == 6 ) echo "</tr>";
}
echo '</table>';

$n_year = $year;
$n_month = $month;
if ($n_month >= 12) {
   $n_month = 1;
   $n_year++;

} else {
  $n_month++;
}


echo '<a href="/?y=' . $n_year . '&m=' . $n_month . '">Next month</a>';
?>

Redagavo Flow
Nuoroda į pranešimą
Dalintis kituose puslapiuose

Kažkas tokio

<?php
$month = isset($_GET['m']) ? $_GET['m'] : date('m');
$year = isset($_GET['y']) ? $_GET['y'] : date('Y');

$first_day_timestamp = mktime(0,0,0,$month,1,$year); 
$maxday = date("t",$first_day_timestamp); 
$thismonth = getdate($first_day_timestamp); 
$startday = $thismonth['wday']-1;
if($startday < 0 ) $startday = 6; 

echo '<table>';
for ($i=0; $i<($maxday+$startday); $i++) {
       if (($i % 7) == 0 ) echo "<tr>";
       if ($i < $startday) { echo "<td> </td>"; continue; };
       $current_day = $i - $startday + 1;
       if ($current_day<10) $current_day = '0'.$current_day;
       echo "<td>". $current_day . "</td>";
       if (($i % 7) == 6 ) echo "</tr>";
}
echo '</table>';

$n_year = $year;
$n_month = $month;
if ($n_month >= 12) {
   $n_month = 1;
   $n_year++;

} else {
  $n_month++;
}


echo '<a href="/?y=' . $n_year . '&m=' . $n_month . '">Next month</a>';
?>

Labai dėkingas.

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Iškilo dar viena problema. Niekaip nesigauna padaryt kad paryškintų dieną su švente, čia mano bandymas:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
.withevent {
background: gold;	
}
</style>
</head>

<body>

<?php
$month = isset($_GET['m']) ? $_GET['m'] : date('n');
$year = isset($_GET['y']) ? $_GET['y'] : date('Y');

$events = array(
array("2014-5-05", 'Svente2', 'Aprasymas2'),
array("2014-6-05", 'Svente', 'Aprasymas')
);

$month_name = array("Sausis", "Vasaris", "Kovas", 
			"Balandis", "Geguze", "Birzelis", 
			"Liepa", "Rugpjutis", "Rugsejis", 
			"Spalis", "Lapkritis", "Gruodis");

$first_day_timestamp = mktime(0,0,0,$month,1,$year); 
$maxday = date("t",$first_day_timestamp); 
$thismonth = getdate($first_day_timestamp); 
$startday = $thismonth['wday']-1;
if($startday < 0 ) $startday = 6; 

$u_year = $year;
$u_month = $month;
if ($u_month >= 12) {
   $u_month = 1;
   $u_year++;
if ($u_month<10) $current_day = '0'.$u_month;
} else $u_month++;

$n_year = $year;
$n_month = $month;
if ($n_month <= 1) {
   $n_month = 12;
   $n_year--;
if ($n_month<10) $current_day = '0'.$n_month;
} else $n_month--;

$output_month_name = date("n",strtotime($year."-".$month."-01"));

echo '<table width="100%" border="1">
 <tr>
     <td><a href="cal2.php?y='.$n_year.'&m='.$n_month.'"><<</a></td>
     <th colspan="5">'.$month_name[$output_month_name-1].', '.date("Y",strtotime($year."-".$month."-01")).'</th>
     <td><a href="cal2.php?y='.$u_year.'&m='.$u_month.'">>></a></td>
 </tr>
 <tr>
     <td class="wDays">Pirmadienis</td>
     <td class="wDays">Antradienis</td>
     <td class="wDays">Treciadienis</td>
     <td class="wDays">Ketvirtadienis</td>
     <td class="wDays">Penktadienis</td>
     <td class="wDays">Sestadienis</td>
     <td class="wDays">Sekmadienis</td>
 </tr>';
for ($i=0; $i<($maxday+$startday); $i++) {
       if (($i % 7) == 0 ) echo "<tr>";
       if ($i < $startday) { echo "<td> </td>"; continue; };
       $current_day = $i - $startday + 1;
       if ($current_day<10) $current_day = '0'.$current_day;

	for($a=0;$a<count($events);$a++) {
		if($events[$a][0] == $year."-".$month."-".$current_day) {
			$start = "class='withevent'";
		} else {
			$start = ""; 
		}
	}

       echo "<td ".$start."><a href='cal2.php?y=".$year."&m=".$month."&d=".$current_day."'>". $current_day . "</a></td>";
       if (($i % 7) == 6 ) echo "</tr>";
}
echo '</table>';

if(isset($_GET['d'])) {
for($i=0;$i<count($events);$i++) {
	if($_GET['y']."-".$_GET['m']."-".$_GET['d'] == $events[$i][0]) {
		echo $events[$i][1]."<br>".$events[$i][2];	
	}
}
}

?>
</body>
</html>

Redagavo Zimex
Nuoroda į pranešimą
Dalintis kituose puslapiuose

Prisijunkite prie diskusijos

Jūs galite rašyti dabar, o registruotis vėliau. Jeigu turite paskyrą, prisijunkite dabar, kad rašytumėte iš savo paskyros.

Svečias
Parašykite atsakymą...

×   Įdėta kaip raiškusis tekstas.   Atkurti formatavimą

  Only 75 emoji are allowed.

×   Nuorodos turinys įdėtas automatiškai.   Rodyti kaip įprastą nuorodą

×   Jūsų anksčiau įrašytas turinys buvo atkurtas.   Išvalyti redaktorių

×   You cannot paste images directly. Upload or insert images from URL.

Įkraunama...
  • Dabar naršo   0 narių

    Nei vienas registruotas narys šiuo metu nežiūri šio puslapio.

  • Prisijunk prie bendruomenės dabar!

    Uždarbis.lt nariai domisi verslo, IT ir asmeninio tobulėjimo temomis, kartu sprendžia problemas, dalinasi žiniomis ir idėjomis, sutinka būsimus verslo partnerius ir dalyvauja gyvuose susitikimuose.

    Užsiregistruok dabar ir galėsi:

    ✔️ Dalyvauti diskusijose;

    ✔️ Kurti naujas temas;

    ✔️ Rašyti atsakymus;

    ✔️ Vertinti kitų žmonių pranešimus;

    ✔️ Susisiekti su bet kuriuo nariu asmeniškai;

    ✔️ Naudotis tamsia dizaino versija;

    ir dar daugiau.

    Registracija trunka ~30 sek. ir yra visiškai nemokama.

  • Naujausios temos

  • Karštos temos

×
×
  • Pasirinkite naujai kuriamo turinio tipą...