วิธีแสดงข้อมูลระหว่างวันที่เริ่มถึงวันที่สิ้นสุด ใน text file ภาษา php ค่ะ
คงจะต้องเก็บ Text File ลงใน Array ก่อนครับ จากนั้นก็ Loop เปรียบเทียบแต่ล่ะ Rows
ถ้าเป็น MySQL นี่ง่ายเลยครับ
Date :
2012-01-18 21:07:50
By :
webmaster
เก็บยังไงดีค่ะหนูนึกภาพไม่ออก พอมีตัวอย่างคร่าวไหมเอ่ย
อันนี้เป็นโค้ดที่ร่วมกันเขียนขึ้นค่ะรบกวนดูให้ทีค่ะ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & Search Text Files</title>
</head>
<body>
<center><h3>Parameter LogBuffer</h3>
<form action="logdrop.php" method="POST">
<select name="month" id="month">
<option value="january" <?PHP if($month==january) echo "selected";?>>January</option>
<option value="february" <?PHP if($month==february) echo "selected";?>>February</option>
<option value="march" <?PHP if($month==march) echo "selected";?>>March</option>
<option value="april" <?PHP if($month==april) echo "selected";?>>April</option>
<option value="may" <?PHP if($month==may) echo "selected";?>>May</option>
<option value="june" <?PHP if($month==june) echo "selected";?>>June</option>
<option value="july" <?PHP if($month==july) echo "selected";?>>July</option>
<option value="august" <?PHP if($month==august) echo "selected";?>>August</option>
<option value="september" <?PHP if($month==september)echo"selected";?>>September</option>
<option value="october" <?PHP if($month==october) echo "selected";?>>October</option>
<option value="november" <?PHP if($month==november) echo "selected";?>>November</option>
<option value="december" <?PHP if($month==december) echo "selected";?>>December</option>
</select>
<select name="day" id="day">
<option value="01" <?PHP if($day==01) echo "selected";?>>1</option>
<option value="02" <?PHP if($day==02) echo "selected";?>>2</option>
<option value="03" <?PHP if($day==03) echo "selected";?>>3</option>
<option value="04" <?PHP if($day==04) echo "selected";?>>4</option>
<option value="05" <?PHP if($day==05) echo "selected";?>>5</option>
<option value="06" <?PHP if($day==06) echo "selected";?>>6</option>
<option value="07" <?PHP if($day==07) echo "selected";?>>7</option>
<option value="08" <?PHP if($day==08) echo "selected";?>>8</option>
<option value="09" <?PHP if($day==09) echo "selected";?>>9</option>
<option value="10" <?PHP if($day==10) echo "selected";?>>10</option>
<option value="11" <?PHP if($day==11) echo "selected";?>>11</option>
<option value="12" <?PHP if($day==12) echo "selected";?>>12</option>
<option value="13" <?PHP if($day==13) echo "selected";?>>13</option>
<option value="14" <?PHP if($day==14) echo "selected";?>>14</option>
<option value="15" <?PHP if($day==15) echo "selected";?>>15</option>
<option value="16" <?PHP if($day==16) echo "selected";?>>16</option>
<option value="17" <?PHP if($day==17) echo "selected";?>>17</option>
<option value="18" <?PHP if($day==18) echo "selected";?>>18</option>
<option value="19" <?PHP if($day==19) echo "selected";?>>19</option>
<option value="20" <?PHP if($day==20) echo "selected";?>>20</option>
<option value="21" <?PHP if($day==21) echo "selected";?>>21</option>
<option value="22" <?PHP if($day==22) echo "selected";?>>22</option>
<option value="23" <?PHP if($day==23) echo "selected";?>>23</option>
<option value="24" <?PHP if($day==24) echo "selected";?>>24</option>
<option value="25" <?PHP if($day==25) echo "selected";?>>25</option>
<option value="26" <?PHP if($day==26) echo "selected";?>>26</option>
<option value="27" <?PHP if($day==27) echo "selected";?>>27</option>
<option value="28" <?PHP if($day==28) echo "selected";?>>28</option>
<option value="29" <?PHP if($day==29) echo "selected";?>>29</option>
<option value="30" <?PHP if($day==30) echo "selected";?>>30</option>
<option value="31" <?PHP if($day==31) echo "selected";?>>31</option>
</select>
<select name="year" id="year">
<?PHP for($i=date("Y"); $i<=date("Y")+9; $i++)
if($year == $i)
echo "<option value='$i' selected>$i</option>";
else
echo "<option value='$i'>$i</option>";
?>
</select>
<h4> To Date </h4>
<select name="month2" id="month2">
<option value="january" <?PHP if($month1==january) echo "selected";?>>January</option>
<option value="february" <?PHP if($month1==february) echo "selected";?>>February</option>
<option value="march" <?PHP if($month1==march) echo "selected";?>>March</option>
<option value="april" <?PHP if($month1==april) echo "selected";?>>April</option>
<option value="may" <?PHP if($month1==may) echo "selected";?>>May</option>
<option value="june" <?PHP if($month1==june) echo "selected";?>>June</option>
<option value="july" <?PHP if($month1==july) echo "selected";?>>July</option>
<option value="august" <?PHP if($month1==august) echo "selected";?>>August</option>
<option value="september" <?PHP if($month1==september)echo"selected";?>>September</option>
<option value="october" <?PHP if($month1==october) echo "selected";?>>October</option>
<option value="november" <?PHP if($month1==november) echo "selected";?>>November</option>
<option value="december" <?PHP if($month1==december) echo "selected";?>>December</option>
</select>
<select name="day2" id="day2">
<option value="01" <?PHP if($day1==01) echo "selected";?>>1</option>
<option value="02" <?PHP if($day1==02) echo "selected";?>>2</option>
<option value="03" <?PHP if($day1==03) echo "selected";?>>3</option>
<option value="04" <?PHP if($day1==04) echo "selected";?>>4</option>
<option value="05" <?PHP if($day1==05) echo "selected";?>>5</option>
<option value="06" <?PHP if($day1==06) echo "selected";?>>6</option>
<option value="07" <?PHP if($day1==07) echo "selected";?>>7</option>
<option value="08" <?PHP if($day1==08) echo "selected";?>>8</option>
<option value="09" <?PHP if($day1==09) echo "selected";?>>9</option>
<option value="10" <?PHP if($day1==10) echo "selected";?>>10</option>
<option value="11" <?PHP if($day1==11) echo "selected";?>>11</option>
<option value="12" <?PHP if($day1==12) echo "selected";?>>12</option>
<option value="13" <?PHP if($day1==13) echo "selected";?>>13</option>
<option value="14" <?PHP if($day1==14) echo "selected";?>>14</option>
<option value="15" <?PHP if($day1==15) echo "selected";?>>15</option>
<option value="16" <?PHP if($day1==16) echo "selected";?>>16</option>
<option value="17" <?PHP if($day1==17) echo "selected";?>>17</option>
<option value="18" <?PHP if($day1==18) echo "selected";?>>18</option>
<option value="19" <?PHP if($day1==19) echo "selected";?>>19</option>
<option value="20" <?PHP if($day1==20) echo "selected";?>>20</option>
<option value="21" <?PHP if($day1==21) echo "selected";?>>21</option>
<option value="22" <?PHP if($day1==22) echo "selected";?>>22</option>
<option value="23" <?PHP if($day1==23) echo "selected";?>>23</option>
<option value="24" <?PHP if($day1==24) echo "selected";?>>24</option>
<option value="25" <?PHP if($day1==25) echo "selected";?>>25</option>
<option value="26" <?PHP if($day1==26) echo "selected";?>>26</option>
<option value="27" <?PHP if($day1==27) echo "selected";?>>27</option>
<option value="28" <?PHP if($day1==28) echo "selected";?>>28</option>
<option value="29" <?PHP if($day1==29) echo "selected";?>>29</option>
<option value="30" <?PHP if($day1==30) echo "selected";?>>30</option>
<option value="31" <?PHP if($day1==31) echo "selected";?>>31</option>
</select>
<select name="year2" id="year2">
<?PHP for($j=date("Y"); $j<=date("Y")+9; $j++)
if($year1 == $j)
echo "<option value='$j' selected>$j</option>";
else
echo "<option value='$j'>$j</option>";
?>
</select>
<br>
<br><input type = "submit" name="submit" value = "Go!">
<input type=button value="Refresh" onClick="javascript:location.reload();"> </br>
</form>
<br>
<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$strFileName = "logfile.txt";
$objFopen = fopen($strFileName,"r");
echo "<table border='1'>"; // opentable
$day1 = $_POST['day2'];
$month1 = $_POST['month2'];
$year1 = $_POST['year2'];
$strFileName1 = "logfile.txt";
$objFopen1 = fopen($strFileName1,"r");
echo "<table border='1'>"; // opentable
echo "<td align= center>$line"; // open column
echo Date;echo "<td align=center>$line"; // show head date
echo Time;echo "<td align=center>$line"; // show head time
echo LogBuffer;echo "\n<tr>"; // show Parameter
while( !feof($objFopen) ) // loop while file
{
$Buffer = fgets($objFopen,4096); // open file = buffer
$Buffer_cut = substr($Buffer,0,9+strlen($month)); // keep in file 0-9 + long month
$Buffer_day = substr($Buffer_cut,6+strlen($month),2);
if(substr($Buffer_cut,8+strlen($month)) == ',') // if Buffer_cut find comma (,) true
{
if((strstr(strtolower($Buffer_day),$day)) AND (strstr(strtolower($Buffer_cut),$month)) AND (strstr(strtolower($Buffer_cut),$year))) // input parameter day,month,year = true
while
{
$numofmonth = 8 + strlen($month);echo "<td>$line"; // count day,year
echo substr($Buffer,0,$numofmonth)."<br>";echo "<td>$line"; // show numofmonth
echo substr($Buffer,$numofmonth+1,8)."<br>";echo "<td>$line"; // cute numofmonth count time or show time
echo substr($Buffer,$numofmonth+10)."<br>";echo "\n<tr>"; // cute numofmonth and count number long.....
}
}
}
}
fclose($objFopen); //close function file
/*while( !feof($objFopen1) ) // loop while file
{
$Buffer1 = fgets($objFopen1,4096); // open file = buffer
$Buffer_cut1 = substr($Buffer1,0,9+strlen($month1)); // keep in file 0-9 + long month
$Buffer_day1 = substr($Buffer_cut1,6+strlen($month1),2);
if(substr($Buffer_cut1,8+strlen($month1)) == ',') // if Buffer_cut find comma (,) true
{
if((strstr(strtolower($Buffer_day1),$day1)) AND (strstr(strtolower($Buffer_cut1),$month1)) AND (strstr(strtolower($Buffer_cut1),$year1))) // input parameter day,month,year = true
{
$numofmonth1 = 8 + strlen($month1);echo "<td>$line"; // count day,year
echo substr($Buffer1,0,$numofmonth1)."<br>";echo "<td>$line"; // show numofmonth
echo substr($Buffer1,$numofmonth1+1,8)."<br>";echo "<td>$line"; // cute numofmonth count time or show time
echo substr($Buffer1,$numofmonth1+10)."<br>";echo "\n<tr>"; // cute numofmonth and count number long.....
}
}
}
fclose($objFopen1); //close function file*/
?></center> </br>
</body>
</html>
หน้าตาออกมางี่ค่ะแต่ยังไม่สมบูรณ์เลย
Date :
2012-01-18 21:46:39
By :
maytaeyeon
Load balance : Server 00