![]() |
![]() |
|
|---|---|---|
| Home|About|Documents | Cool Stuff |Links|Contact| |
| The code to do date comparison Version 1 |
| Date comparison Version 2 |
| Email with various options ... |
| Array Sorting code... |
| Download with date wise sorting of the documents |
| C# using custom color for a row based on column color |
| Intersection of two arrays when comparison is based on only 1 key |
The code to do date comparison Version 1 - |
| //this function compares any date to current date and returns results
in form of integers function date_compare ( $b_year, $b_month, $b_day ) { $today = getdate(); $a_year = $today["year"]; $a_month = $today["mon"]; $a_day = $today["mday"]; $final_result = 9; //set it to random right now if($a_year < $b_year) { $final_result = 1; //the given year is greater then current year..so the date is in the future.. }//year greater else if($a_year == $b_year) //the years are the same ..so check the month { if($a_month < $b_month) { $final_result = 2; //the given month is greater then current month so date is in the future }//greater month check else if($a_month == $b_month)//same months ..so check dates { if($a_day < $b_day) { $final_result = 3; //the given date is greatter then current date... } else if($a_day == $b_day) { $final_result = 4; //the dates are identical too..so date1 becomes equal to date 2 } else { $final_result = -3; //the date1 < $date 2 } }//equal month check else { $final_result = -2; }//month1 < month2 }//year same else { $final_result = -1; //the year 1 is smaller then year 2 ..hence date1 < date2 } return $final_result; } |
Date comparison Version 2 |
PHP lets you convert string into time and the time is in seconds ...so simple method to compare dates would be convert them into seconds and then substract them to find out the values.....Here is an example where I used it.... function getQuarter($recordDate, $current_year) //quarter 2 //quarter 3 //quarter 4 if(($ts1_s<=0)&&($ts1_e>=0)) |
Email with various options ... |
| This code was written to send email to Gamma Phi members based on various conditions... - http://www.exu.ilstu.edu/gamma_phi/admin/admin.phtml?file=e-mail.inc |
| <? //--Written August 2005 by Abhilasha Sharma //--EXU - Illinois State Extended University //--Email Application for the gamma_phi website... ?> <!--*************************************************************************************************************--> <!--*************************************************************************************************************--> <!--*************************************************************************************************************--> <!--Pop Up for the help window...--> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=500,left = 600,top = 100');"); } // End --> </script> <!--*****Content Section*****--> //the function where the actual mail sending is occuring $count_member=count($member_set); $to = "ajlight@ilstu.edu, jabinni@ilstu.edu, asharm4@ilstu.edu"; //this is special processing for the select member mailing option if($selectmember==1) $to = " "; for($i=0;$i<$count_member;$i++) print "The mail sent successfully from the address ".$from."
to the following members :- "; for($i=0;$i<$count_member;$i++)
/*cleaning up the message and subject*/ $subject = str_replace("\'",' ',$subject); // Read POST request params into global vars $member_data_query = "SELECT email, login, lname, fname from
member order by lname"; $from = ""; $headers = "From: $from"; if (is_uploaded_file($fileatt)) { // Generate a boundary string // Add the headers for a file attachment // Add a multipart boundary above the plain message // Base64 encode the file data // Add file attachment to the message /*Function to mail to only the admin members of the website*/ print "<form action='member.phtml?file=e-mail_member.inc&selectmember=1'
method='POST' enctype='multipart/form-data'>"; print "</tr>"; }//select member query </tr> <? |
Array Sorting code... |
| This code was written for RSP website because they wanted sorting of data in run time...So, here is the page that uses it..and the code - http://reports.rsp.ilstu.edu/container.phtml?file=type_of_grant&season=FY06&quarter=0&college=ALL |
| /******************************************************************************************** Set the different sort orders here */ if($orderby=='typeofgrant') if($orderby=='proposals') if($orderby=='requested') if($orderby=='awards') if($orderby=='recieved')
|
Download with date wise sorting of the documents |
| I took the downloads function already present for the EU..(I think sharik wrote it...) and modified it to have the date wise sorting of the documents. Also, added the catch where the current working directory is computed at the run time as compared to hard coded one in the older code... |
| function list_download() { $retVal = array(); } //--End list_downloads function |
C# using custom color for a row based on column color |
Step 1 -- make yourself a datagrid <asp:DataGrid id="DataGrid1" AutoGenerateColumns =false
style="Z-INDEX: 101; LEFT: 18px; POSITION: absolute; TOP: 18px"
runat="server">
Step 2 - In the code behind write the code which picks the color based on the value of the UnitsInStock. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load 'Function to pick up the color based on th UnitsInStock Value
Source - http://www.c-sharpcorner.com/Code/2003/May/ChangeDataGridColumnColor.asp |
Intersection of two arrays when comparison is based on only 1 key |
| A function to find intersection of two arrays when comparison is based
on only 1 key
function array_common($array1,$array2,$compareString) { } |