Jump to content
php.lv forumi

Nolasīšana No Mysql


Kaspars

Recommended Posts

Sveiki,

 

Man ir tabula ieksh mysql, kuraa ir sekojoshais: id, notikuma laiks, notikuma apraksts.

Lieta taada ka veelos dabuut araa laukus, kas ir kaaadaa notikuma laika intervaalaa. Kaa lai to izdara. Ir meeginaats sekojosh variants

 

<code><font color="#000000">

<font color="#0000CC"><?

$Year </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y"</font><font color="#006600">);
</font><font color="#0000CC">$Month </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"m"</font><font color="#006600">);
</font><font color="#0000CC">$Day </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"d"</font><font color="#006600">);
</font><font color="#0000CC">$StopDate </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y-m-d"</font><font color="#006600">, </font><font color="#0000CC">[url=http://lv.php.net/mktime]mktime[/url]</font><font color="#006600">(</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$Month</font><font color="#006600">, (</font><font color="#0000CC">$Day </font><font color="#006600">+ </font><font color="#0000CC">10</font><font color="#006600">), </font><font color="#0000CC">$Year</font><font color="#006600">));
</font><font color="#0000CC">$StartDate </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y-m-d"</font><font color="#006600">);
echo(</font><font color="#0000CC">$StartDate</font><font color="#006600">);
echo(</font><font color="#0000CC">$StopDate</font><font color="#006600">);

</font><font color="#0000CC">$query </font><font color="#006600">= </font><font color="#CC0000">"SELECT date_format(datums, '%Y %d, %m') FROM kalendars WHERE ('$datums' > StartDate )"</font><font color="#006600">;
</font><font color="#0000CC">$result </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_query]mysql_query[/url]</font><font color="#006600">(</font><font color="#0000CC">$query</font><font color="#006600">);
</font><font color="#0000CC">?>
</font>
</font>
</code>

 

p.s. datums ir datubazes lauks kuraa ir konkreetaa notikuma datums.

Kopeejaa ideja taada, ka uz ekraana izdrukaa visus notikumus kas veeel buus, piemeeram 10 dienas uz priekshu.

Link to comment
Share on other sites

Jutaajums: kaads tev ir laika lauks - timestamp, date?

Ja buutu kaads timestamp, tad vareetu dziit iexhaa ar mktime() un dabuut arraaa ar FROM_UNIXTIME(mktime()+/-vajadziigais laix sekundees) un vispaar tas Unix timestamps man liekas elastiigaaks. Tur ar vienu date("n") (neaceros, vai bija "n") vareeja dabuut dinas skaitu gadaa un tad saliidzinaat tos...

Link to comment
Share on other sites

Paraknaajos pa manuaaljiem un veel visaaadi, beidzot pieveicu. Ja kaadam ir interese, luuk shitaa taa lieta straadaa: datums ir mysql lauks timestamp(8), kas noziiimee formaats GGGG-MM-DD. paareejais amptuveni saprotams taa pat:

 

<code><font color="#000000">

<font color="#0000CC"><?
$Year </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y"</font><font color="#006600">);
</font><font color="#0000CC">$Month </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"m"</font><font color="#006600">);
</font><font color="#0000CC">$Day </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"d"</font><font color="#006600">);

</font><font color="#0000CC">$StopDate </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y-m-d"</font><font color="#006600">, </font><font color="#0000CC">[url=http://lv.php.net/mktime]mktime[/url]</font><font color="#006600">(</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">0</font><font color="#006600">,</font><font color="#0000CC">$Month</font><font color="#006600">, (</font><font color="#0000CC">$Day </font><font color="#006600">+ </font><font color="#0000CC">20</font><font color="#006600">), </font><font color="#0000CC">$Year</font><font color="#006600">));
</font><font color="#0000CC">$StartDate </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/date]date[/url]</font><font color="#006600">(</font><font color="#CC0000">"Y-m-d"</font><font color="#006600">);
</font><font color="#0000CC">$MenesisLV </font><font color="#006600">= array (</font><font color="#CC0000">"janvaris"</font><font color="#006600">, </font><font color="#CC0000">"februaris"</font><font color="#006600">, </font><font color="#CC0000">"marts"</font><font color="#006600">, </font><font color="#CC0000">"apr¾lis"</font><font color="#006600">, </font><font color="#CC0000">"maijs"</font><font color="#006600">, </font><font color="#CC0000">"jĖnijs"</font><font color="#006600">,</font><font color="#CC0000">"jĖlijs"</font><font color="#006600">, </font><font color="#CC0000">"augusts"</font><font color="#006600">, </font><font color="#CC0000">"septembris"</font><font color="#006600">, </font><font color="#CC0000">"oktobris"</font><font color="#006600">, </font><font color="#CC0000">"novembris"</font><font color="#006600">, </font><font color="#CC0000">"decembris"</font><font color="#006600">);

if (</font><font color="#0000CC">$id</font><font color="#006600">) {
</font><font color="#FF9900">// saak mekleet papildus info  dayofmonth(datums) as die, month(datums) as men, year(datums) as gad, notikums, pilns_notikums, id
</font><font color="#0000CC">$sql </font><font color="#006600">= </font><font color="#CC0000">"SELECT dayofmonth(datums) as die, month(datums) as men, year(datums) as gad, notikums, pilns_notikums, id FROM kalendars WHERE id=$id"</font><font color="#006600">;
</font><font color="#0000CC">$res </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_query]mysql_query[/url]</font><font color="#006600">(</font><font color="#0000CC">$sql</font><font color="#006600">);
</font><font color="#0000CC">$myrow </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_fetch_row]mysql_fetch_row[/url]</font><font color="#006600">(</font><font color="#0000CC">$res</font><font color="#006600">);

 } else {

</font><font color="#0000CC">$query </font><font color="#006600">= </font><font color="#CC0000">"SELECT dayofmonth(datums) as diena, month(datums) as menesis, year(datums) as gads, notikums, id FROM kalendars WHERE ((datums >= '$StartDate') AND (datums <= '$StopDate')) ORDER BY datums ASC"</font><font color="#006600">;
</font><font color="#0000CC">$result </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_query]mysql_query[/url]</font><font color="#006600">(</font><font color="#0000CC">$query</font><font color="#006600">);

echo </font><font color="#CC0000">"No:   <i>$StartDate</i><br/>L¾dz: <i>$StopDate</i><br/>"</font><font color="#006600">;
echo (</font><font color="#CC0000">"<b>N²kam²s sacens¾bas:</b>"</font><font color="#006600">);
echo (</font><font color="#CC0000">"<table border = '0' width = '100%' align='left'>"</font><font color="#006600">);

	while (</font><font color="#0000CC">$rows </font><font color="#006600">= </font><font color="#0000CC">[url=http://lv.php.net/mysql_fetch_row]mysql_fetch_row[/url]</font><font color="#006600">(</font><font color="#0000CC">$result</font><font color="#006600">))
	</font><font color="#FF9900">// printee arra notikumus
	</font><font color="#006600">{
	</font><font color="#0000CC">$menesis </font><font color="#006600">= </font><font color="#0000CC">$rows</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">];
	echo (</font><font color="#CC0000">"<tr><td><b><font face="</font><font color="#0000CC">arial</font><font color="#CC0000">" size="</font><font color="#0000CC">2</font><font color="#CC0000">">$rows</font><font color="#006600">[</font><font color="#CC0000">0</font><font color="#006600">]</font><font color="#CC0000">. $MenesisLV</font><font color="#006600">[</font><font color="#CC0000">$menesis</font><font color="#006600">]</font><font color="#CC0000">, $rows</font><font color="#006600">[</font><font color="#CC0000">2</font><font color="#006600">]</font><font color="#CC0000"></font></b><br/><font face="</font><font color="#0000CC">arial</font><font color="#CC0000">" size="</font><font color="#0000CC">2</font><font color="#CC0000">">$rows</font><font color="#006600">[</font><font color="#CC0000">3</font><font color="#006600">]</font><font color="#CC0000"></font><br/><a href="</font><font color="#006600">?</font><font color="#0000CC">id</font><font color="#006600">=</font><font color="#0000CC">$rows</font><font color="#006600">[</font><font color="#0000CC">4</font><font color="#006600">]</font><font color="#CC0000">"><font color="</font><font color="#0000CC">red</font><font color="#CC0000">" face="</font><font color="#0000CC">Fixedsys</font><font color="#CC0000">">><font face="</font><font color="#0000CC">arial</font><font color="#CC0000">" color="</font><font color="#0000CC">black</font><font color="#CC0000">" size="</font><font color="#0000CC">2</font><font color="#CC0000">"> vair²k</font></a><hr size="</font><font color="#0000CC">1</font><font color="#CC0000">" noshade></td></tr></font>"</font><font color="#006600">);
	}
	</font><font color="#FF9900">// aiver ciet table
</font><font color="#006600">echo </font><font color="#CC0000">"</table>"</font><font color="#006600">;
}
</font><font color="#0000CC">?>
</font>
</font>
</code>

Link to comment
Share on other sites

×
×
  • Create New...