|
25-03-2005, 09:32
|
מנהל פורומי "תכנות ובניית אתרים" ו"חומרה ורשתות"
|
|
חבר מתאריך: 25.10.01
הודעות: 42,776
|
|
למרות שהוא כבר ענה על התשובה, יש קוד ארוך ומלא יותר שכתבתי לפני הרבה זמן...
כעקרון, זה על מנת לחפש נתונים במסד, בשאילתא המבוססת על unixtime, ובהגבלה למספר תוצאות (אם רוצים). יש הגבלה פנימית ל 500 תוצאות חיפוש, כדי שלא ישחטו את ה DB על ידי שינוי הטופס באופן עצמאי
קוד PHP:
<? function draw_select_pullbox($name, $min, $max, $jumps) { $out = "\n <select name=\"$name\">\n"; for($cnt=$min; $cnt<=$max; $cnt=$cnt+$jumps) { $out .= " <option value=\"$cnt\">"; $out .= str_pad($cnt, 2, 0, STR_PAD_LEFT); $out .= "</option>\n"; } $out .= " </select>"; return $out; }
if (!isset($_GET['op'])) { ?> <!-- No action selected, display search form! --> <form action="<?=$_SERVER["PHP_SELF"];?>" method="get"> <input type="hidden" name="op" value="search"> <table border="0" cellspacing="0" cellpadding="1" align="center"> <tr> <td> <table border="0" cellspacing="0" cellpadding="0" width="100%"> <tr> <td> <center><u>Search Form</u></center> <table border="0"> <tr> <td align="left">Starting date and time:</td>
<td> <?=draw_select_pullbox("sd", 1, 31, 1) . " / " . draw_select_pullbox("smo", 1, 12, 1) . " / " . draw_select_pullbox("sy", 2002, date('Y'), 1) . " at " . draw_select_pullbox("sh", 0, 23, 1) . " : " . draw_select_pullbox("smi", 0, 59, 1) . " : " . draw_select_pullbox("ss", 0, 59, 1); ?> </td>
</tr> <tr> <td align="left">Ending date and time:</td>
<td> <?=draw_select_pullbox("ed", 1, 31, 1) . " / " . draw_select_pullbox("emo", 1, 12, 1) . " / " . draw_select_pullbox("ey", 2002, date('Y'), 1) . " at " . draw_select_pullbox("eh", 0, 23, 1) . " : " . draw_select_pullbox("emi", 0, 59, 1) . " : " . draw_select_pullbox("es", 0, 59, 1); ?> </td> </tr> <tr> <td> Limit number of results to: </td> <td> <?=draw_select_pullbox("maxresults", 50, 500, 50);?> </td> </tr> </table> <center> <input type="submit" value="Run search"> </center> </td> </tr> </tr> </table> </td> </tr> </table> </td>
</tr> </table> </form> <? if ($_GET['op'] == "search") {
$sd = $_GET["sd"]; // start day $smo = $_GET["smo"]; // start month $sy = $_GET["sy"]; // start year $sh = $_GET["sh"]; // start hour $smi = $_GET["smi"]; // start minute $ss = $_GET["ss"]; // start second
$ed = $_GET["ed"]; // end day $emo = $_GET["emo"]; // end month $ey = $_GET["ey"]; // end year $eh = $_GET["eh"]; // end hour $emi = $_GET["emi"]; // end minute $es = $_GET["es"]; // end second
$maxresults = $_GET["maxresults"]; // Get value for MySQL's LIMIT function...
checkdate($smo, $sd, $sy) or die("You've entered a start date that does not exist in the calendar !!!"); checkdate($emo, $ed, $ey) or die("You've entered an end date that does not exist in the calendar !!!");
if ($sh < 0 || $sh > 23) die("Are you trying to fuck up with my script? :) Not today, you're not..."); if ($smi < 0 || $smi > 59) die("Are you trying to fuck up with my script? :) Not today, you're not..."); if ($ss < 0 || $ss > 59) die("Are you trying to fuck up with my script? :) Not today, you're not..."); if ($eh < 0 || $eh > 23) die("Are you trying to fuck up with my script? :) Not today, you're not..."); if ($emi < 0 || $emi > 59) die("Are you trying to fuck up with my script? :) Not today, you're not..."); if ($es < 0 || $es > 59) die("Are you trying to fuck up with my script? :) Not today, you're not...");
if ($maxresults < 1 || $maxresults > 500) die("The limit is between 1 and 500. Don't try to override me!");
$from = mktime($sh, $smi, $ss, $smo, $sd, $sy); $to = mktime($eh, $emi, $es, $emo, $ed, $ey); if ($to == $from) die("You chose the exact same start and end times..."); if (($to - $from) < 0) die("Your start date is after your end date..."); ?>
ואפשר להשתמש ב to$ ו from$ המכילים את ה unixtime-ים של ההתחלה והסוף...
|
|