Category Archives: Web Design

A bit of php programming…

I do this type of programming about 4 times a year and each time I have to lookup how to compare dates in php. There are so many options and some make it out to be so complicated I thought I would just thru my answer into the pool. The following code is used to display a message depending on the date. Basically it announces a business will be closed for a holiday.

I use a multidimensional array to hold the holiday information, then go thru it to see if it needs to be displayed. This is also setup so that more than one message could appear at any given time (usually around Christmas & New Years). As you can see from my array, I supplied 2 dates – start date and end date.

array definition: collection = array(start date, end date, first line of message, second line of message)

php code :

<?

$holidays = array(
“Easter”=>array(‘2013-03-20′,’2013-03-30′,’Friday March 29th’,’in recognition of Good Friday’),
“MemDay”=>array(‘2013-05-15′,’2013-05-28′,’Monday May 27th’,’in recognition of Memorial Day’),
“IndDay”=>array(‘2013-06-25′,’2013-07-05′,’Thursday July 4th’,’in recognition of the 4th of July’),
“LabDay”=>array(‘2013-08-15′,’2013-09-03′,’Monday September 2nd’,’in recognition of Labor Day’),
“Christmas”=>array(‘2013-12-10′,’2013-12-26′,’Tues December 24th & Wed, December 25th’,’in recognition of Christmas’),
“NewYear”=>array(‘2013-12-12′,’2014-01-02′,’Wed January 1st’,’in recognition of New Years Day’)
);

$txtMsg = ‘<p>We will be closed<br /> ‘;
$MsgCount = 0;
$today = date(“Y-m-d”);
foreach ($holidays as $value)
{

if (date($value[0])<$today && date($value[1])>$today)
{
$msgCount++;
$txtMsg .= ‘* <span>’.$value[2].'</span> * <br />’;
$txtMsg .= $value[3].'</p>’;
}
}

if ($msgCount >0) {
print $txtMsg;
}

?>

I could have had the php code write out the day of the week, Month name etc, but because of limited space where this is being placed on the web page, I wanted to control what was displayed. For example, where Christmas is 2 days, writing out the complete names of the days would have caused it to wrap around and look out of place on the web page. But you sure could do that if you wanted to.

I actually have an excel worksheet that has this data in it and does the calculations for me to set the start date 10 days ahead of the shutdown date.

Web Hosting Options

My 3 favorite hosting options (in no specific order):

  • pair.com – I have hosted with pair.com for 15+ years and I have never had an outage or interruption of the service. They used to be more for the hands on web master that doesn’t need or want a graphical interface to do things. They have recently introduced a new Control Panel that will walk you through any and every thing you want to do. I highly recommend them.

  • justhost.com – I have hosted with justhost.com for the past 5 years or so. They offer unlimited hosting of domain names. They have a great control panel that offers you all the options you need or want. Lots of space for websites and email. I highly recommend them.
  • godaddy.com – I have worked with many sites that are using godaddy.com hosting services, some options they are are better than others. Recently they started offering WordPress as an option. The only “con” I have for them is that some of their web site building applications have a slow response when you are creating. But they do offer so many deals it’s hard to not like these guys.

Find the Index number of an item in a Javascript Array

I recently was creating a quoting form for a company that I was working for and I wanted to streamline as much as possible (i love to combine things or as I say, get more for my money!). When the quote was completed it would return a description of the items ordered and assign a Smart Part Number to the configuration.

  • So I have a list of categories – with options, setup as radio buttons.
  • When a selection is made I want to load that item (description, price, partNo) into the display area.
  • And build and display the Smart Part number.

TASK: The order in which the items are displayed and added to the display area is very important, so I coded the radio buttons with an ID – then I lookup that ID in an array and get the index number (order number) of that item and that is the placement in the smart part number.

Here is the javascript code I used to do that:

<SCRIPT language = "JavaScript">

//define array outside of a function to make it universally available
var arrPNC = [ "00", "A", "B", "C", "D", "E", "F", "G", "H"];
var itemOrder = 0;

//function to do the lookup and return index(order) must pass a letter
function findItem(tComp){
    findVal=tComp.value  //gets the value from the radio button
	//alert(findVal);  //if you want to see what is being searched for
    for(n=0;n<9;n++){
        //alert(arrPNC[n]); // if you want to see what is checked
        if(arrPNC[n]==findVal)
         {//if matches break from loop and get the index
            itemOrder = n;
        }
    }
     if (itemOrder > 0 ){       
       alert(findVal+ " is in position " + itemOrder + " in the array");
     } else {
       alert(findVal + " was not found in the array. Please try again.");
     }
     itemOrder = 0;
}
</script>

Example of the radio button input tag:
<input id="F" onclick="findItem(this);" type="radio" name="B" value="F" />F

Try it select an item below:

A  B  C   D   E   F   G   H   I

Show your work!!!!!

During a recent job interview, I was given a programming test / quiz – which I botched up royally – I froze. And no, I didn’t get the job. So in the spirit of my math teachers – I’m going to ‘Show My Work’.

The test was to write the code to display numbers 1-100, if divisible by 3 – write “Yeah”, if divisible by 5 – write “Baby”, if divisible by both – “Yeah Baby”. I didn’t freeze because I didn’t know how to do the “for/while” statements/loop or the “if” statements, it was because I had never had to check for a WHOLE number before. So my mind was racing on a small detail of the question – in my mind an important part of the question (but not to them I guess). Well, I now know how to check for a whole number in 3 different ways. Something learned!!!

So here are my 3 versions (I have a tendency to be dramatic you know):

JavaScript:

<script type="text/javascript">
function YB(){
    for(i=1;i<=100;i++)
    {
        x = i/3;
        y = i/5;
        if(x == parseInt(x)){
            a = " Yeah";
        }
        if (y == parseInt(y)){
            a = a+ " Baby";
        }

        document.write(i+" "+a+" <br />");
        a = "";
    }
}

</script>

PHP:

for ($i =1; $i<=100; $i++)
{
    if($i % 3 == 0){
        $a = " Yeah";
    }
    if($i % 5 == 0){
        $a .= " Baby";
    }
    print $i." ".$a."<br />";
    $a = "";
}

Java:

public class yeahBaby{
    public static void main(String[] args) {
        for(double i =1; i <= 100; i=i+1)
        {
            String a = "";
            double x = i/3;
            double y = i/5;
            if(x == Math.rint(x)){
                a = " Yeah";
            }
            if(y == Math.rint(y)){
                a = a+ " Baby";
            }
            System.out.println(Math.round(i)+" "+a);
        }
    }
}

Another Ad Provider / Tracker

So I was doing some reading on the internet this weekend – staying out of the heat and humidity and I ran across a site that was rating the new rash of “Single deal” sites that are now out there (like Groupon), and they also talked about this as service that they use. Although the first thing they mention is not have have too many of these links/areas on your webpage or it will start to look cheesey. Then I looked around their layout – they had 8 different areas for ads on their page. Hmmmm?

Anyway – you get credit when people sign up as advertisers (company for them to push their ads) and publishers (you display those ads). Well at least their site didn’t have typos on it like another one that I ran across this weekend.


I signed up for a new ad service this weekend, just to try something different:

It’s another ad servicing site, but I thought I would give it a try.

php Multidimensional arrays

Lately I have been working on some small snippets of code to automate tasks I do often, yet not often. I do them so rarely that I forget how I did it the last time. But yet, I have to do it every year – well around every holiday at least.

I take care of an international webpage for a customer service department. I need to post the holiday shutdown schedule when we come close to a holiday. Luckily there are only 6 of them. So to automate the message I finally sat down and wrote this snippet to automatically display the message about a closing day 14 days before the holiday – it’s more reliable that I am to update itself.

Is it the best way? Maybe, maybe not.
Is it the only way? Absolutely not.
But this works for what I need. I update it once a year when our company releases it’s shutdown schedule.

I am using a multidimensional array, I’ve set the key for the 2nd level.

Here it is:

<?
$tToday = date("Y-m-d");
//array structure:   array( startdate, enddate, displaydate, holiday);
$wSched = array(0 => array( '2012-1-1', '2012-1-2', '2011-12-18', 'New Years'),
    1 => array( '2011-5-30','2011-5-30', '2011-5-16', 'Memorial Day'),
    2 => array( '2011-7-4', '2011-7-4', '2011-6-20', 'July 4th'),
    3 => array( '2011-9-5', '2011-9-5', '2011-8-22', 'Labor Day'),
    4 => array( '2011-11-24', '2011-11-28', '2011-11-10', 'Thanksgiving'),
    5 => array( '2011-12-26', '2011-12-27', '2011-12-12', 'Christmas'));

$tMsg = "<h2>ATTENTION</h2>";
$tMsgL = strlen($tMsg);
asort($wSched);
 for ($col=0; $col <6; $col++)
  { 
   if(strtotime($tToday) >= strtotime($wSched[$col][2]) && strtotime($tToday) <=
strtotime($wSched[$col][1]) )
    {          
      $tMsg.= "<p>Mate will be closed on <br />".date("D, F j, Y",
strtotime($wSched[$col][0]));
      if ( strtotime($wSched[$col][1]) != strtotime($wSched[$col][0]) )  
         {
           $tMsg .= " thru ".date("D, F j, Y", strtotime($wSched[$col][1]));
         }
      $tMsg .= "<br /> in observation of ".$wSched[$col][3]." Holiday</p>";
    };  

  }; //end for

if (strlen($tMsg)> $tMsgL)
{
   print $tMsg;
};
?>