By Brian, 1 year and 3 months ago

It's My Birthday, and I'll post if I want to :)

It seems like only yesterday that I was sitting in my parents house on a Win3.1 box with 8 MB of ram that cost 5 grand, on AOL v1.0 playing Minesweeper. The reality of it, is that was merely 10 years ago. Computers have changed so much in these past years, and looking back at myself, I too have changed.

While I'd like to think that I've become cheaper to own, easier to operate, and can do more things, I think I'd just be kidding myself. At least on the first two.

It's fun to check your mail on your birthday. Of course, all my friends didn't send me anything, but every forum I've ever registered at did. Half of them, I didn't even realize I had an account on. I must've gotten 30-40 emails from random sites that I don't even remember registering at.

Perhaps this is a marketing lesson. Send birthday emails out to everyone who hasn't logged in in over 6 months 4 times a year. Sure, you'll get the «hey, its not my birthday» responses, but it will remind them that they have an account there, and maybe re-spark an interest that died or slipped the mind.

Anyway, time to party (yeah right, Its 3am on my b-day morning, and i'm working :( ).
27... damn. I'm old :(

-B

By Brian, 1 year and 3 months ago

The Fall of CPC Advertising, Part Deux: Yahoo buys Right Media

earlier this month, Google announced its purchase of DoubleClick. Today, the news is out that Yahoo has bought Right Media. The fall of CPC advertising is coming soon. :(

By Brian, 1 year and 4 months ago

The Fall of CPC Advertising

Announced just a few minuets ago, Google has purchased DoubleClick for $3 Billion and change. (Source: NyTimes)

This is a huge buy in many respects, but the one that effects me as a web publisher the most, is that once again, our options for dealing with providers has been literally cut in half.

As you probably noticed on this page, I run Adsense here and on the majority of my sites. Through hard trial and error, its proven to be the best converting provider for me and my content.

Will buying into the CPM and CPA programs be the fall of the CPC focus? I've NEVER made good money or conversion rates with CPA offers and ads. In order to secure my income, i need CPC ads to stay popular, and keep the fresh advertisers coming into the Adwords program. If this new buy takes away from the CPC side of things, I may be in for a global shut down as lord knows I cannot afford to pay a $500 server bill every month out of pocket.

Do you think that Google will start to loose focus on its CPC advertising and start putting more effort into CPA? They have already started this with their referrals and products programs through Adsense, and I think that may have been the stepping stone to move away from CPC.

By Brian, 1 year and 7 months ago

Scripting Around Poor Table Design

We've all seen it. Some 3rd party database you've inherited from someone else was simply never designed with scalability and portability in mind. There's no hope to change it, as it will break the original design and thus the original application that it is supporting.

Keep reading →

By Brian, 1 year and 7 months ago

Quick SQL Date Functions and Queries

It's easy to grab the date from a field in a database so long as you saved a timestamp field along with your data row. However, there are often times in developing stored procedures and advanced queries where one needs to look up events in the future, or past based on some other reference point from either the data at hand, or an arbitrary date, such as in a calendar.

Keep reading →

By Brian, 1 year and 7 months ago

RFC-32 Date Formatting with Classic ASP

Tonight I was working on an RSS package for a client of mine. Having dealt with RSS feeds in the past, I figured it wouldn't be a big deal. However, my experience with them has always been on the 'receiving' end of it, imploding out the <item></item>'s and making sense of the xml.

For the most part, setting up the RSS2.0 feed was pretty straight forward. The one thing that took a little time to manipulate was the RFC-32 date/time formatting that RSS Feeds require in order to validate. And we all know how important validation is :)

Keep reading →

By Brian, 2 years ago

Lightbox and WordPress- The Easy Way

I recently wrote an article on BloggerSkills.com on how to better utilize the Lightbox functions within a WordPress blog. No more manually typing rel=»lightbox» attributes!

read more | digg story

By Brian, 2 years and 2 months ago

Getting Loopy - Nested Javascript Loops

Complex loops with Javascript can get tricky. Double-nested loops, dynamic field names, and all kinds of other things can leave a programmers head spinning. Let's get Loopy and tackle this in a nice programatical manner.

Recently presented with a form similar to a questionaire, there were a bunch of questions, each with the possibility of multiple answer options and a comment box. To make matters worse, I needed to check if there were comments entered when a certain option was selected. Rather than go through one by one and create a huge function, I tapped into the power of loops, and the power of dynamic form element naming.

Let's say our form is a questionaire with radio buttons for options and a comment box. The form would look something like this:

  1. <div>
  2.   <form id="frmdefault" onsubmit="validateForm();" method="post" action="results.php">
  3.     <table>  
  4.       <tr>
  5.         <td>Q1</td>
  6.         <td><strong>How good are you at javascript?</strong></td>
  7.         <td><input type="radio" id="q1" name="q1" value="Great" />Great!</td>
  8.         <td><input type="radio" id="q1" name="q1" value="Average" />Average</td>
  9.         <td><input type="radio" id="q1" name="q1" value="Bad" />Bad</td>
  10.         <td><input type="radio" id="q1" name="q1" value="NA" />N/A</td>  
  11.         <td><textarea id="q1_comments" name="q1_comments" rows="2" cols="5"></textarea></td>
  12.       </tr>
  13.       <tr>
  14.         <td>Q2</td>
  15.         <td><strong>How do you think this tutorial rates?</strong></td>
  16.         <td><input type="radio" id="q2" name="q2" value="Great" />Great!</td>
  17.         <td><input type="radio" id="q2" name="q2" value="Average" />Average</td>
  18.         <td><input type="radio" id="q2" name="q2" value="Bad" />Bad</td>
  19.         <td><input type="radio" id="q2" name="q2" value="NA" />N/A</td>  
  20.         <td><textarea id="q2_comments" name="q2_comments" rows="2" cols="5"></textarea></td>
  21.       </tr>
  22.       <tr>
  23.         <td colspan="7"><input type="submit" value="Validate Form" /></td>
  24.       </tr>
  25.     </table>
  26.   </form>
  27. </div>

This makes our nice little form. Of course, you can make it into nice table-less layout and all that, but that is beyond the scope of this article, so I used a table.

Let's say that we want to:

  1. Make sure a radio option is selected for each question
  2. require a comment to be entered in the textarea if «Bad» is selected

In order to do this, we need to first loop through our radio buttons to see if one is selected. If «bad» is selected, prompt for comments to be entered. Finally, we need to loop and repeat the above for every question.

In less than 30 lines of (well-formatted) code, we can set up a double-looping function that does all of this, will work for an infinite amount of questions or possible answers (except a single answer- but, you shouldn't be using radio buttons for a single element choice anyway). I will explain the code below the function:

  1. <script type="text/javascript">
  2.  
  3. function validateForm() {
  4.   var theform = document.getElementById("frmdefault");
  5.  
  6.   for (i=1; i&lt;3; i++)
  7.   {
  8.     for (j=0; j<theform .elements["q"+i].length; j++)
  9.     {
  10.       if (theform.elements["q"+i][j].checked)
  11.       {
  12.         if (theform.elements["q"+i][j].value == "Bad")
  13.         {
  14.           if(theform.elements["q"+i+"_comments"].value == "")
  15.           {
  16.             alert("Comments required for Q"+i+" when Bad is selected");
  17.             theform.elements["q"+i+"_comments"].focus();
  18.             return false;
  19.           }
  20.         }
  21.       }
  22.       else
  23.       {
  24.         alert("Please select an option");
  25.         return false;
  26.       }
  27.     }
  28.   }
  29. }
  30. </script>
  31. </theform></script>

It looks very complex and tricky, but as we go through it you will see it makes a lot of sense. The outer loop is set for the number of questions we have. In this case, we have 2. You could port this a step further an make this number count dynamic as well. (In most cases though, I feel as if that's an un-necessary step as most polls or scripts like this won't change once made. If you are running some kind of dynamic form generator, then yes, another step will need to be added to find how many questions there are. Basically, you'd have to add another loop around all of the above that counts how many questions there are.)

Notice, we start with i=1 instead of the common i=0. This is because our questionaire starts with question 1, not question 0. It makes things easier to address in the inner functions. Because of this, we also must up our incremented variable to i<3 instead of i<2, because of the increased initialized variable. Another option would be to use i< =2, thus allowing for it to be equal to the max index.

The outer loop, i, will call the inner loop j, i times. Inside the inner loop, we need to dynamically address how many radio buttons there are. The length function figures this out for us and begins our data check to ensure at least one element is checked per our requirements. Note that we are using [«q»+i]. This evaluates to our question number based off the outer loop. If the element array does not have one checked, it will return false and prompt the user to select one. If there is an element checked, it will then look and see if that checked value = «Bad». If it is, it then checks to see if there is anything in the textarea field for comments. If not, we return home free and we return to the outer loop for testing the question count to see if we need to do this all over again for the next question, if one exists. When all is passed, the form will submit to the target in the action attribute of the form tag, in our example, results.php.

Of course, this all depends on Javascript being enabled, and in a browser than supports the getElementById() functionality. Thus, it is important to also use server-side scripting to double check the submitted results. The Javascript just adds a friendly alert so that the whole page doesn't need to be submitted every time an error occurs.

Have a better idea? I'm sure this code can be improved upon, and thus I'm curious to hear if anyone else has a similar function set up for this type of form checking. I appreciate your comments, as always.

By Brian, 2 years and 2 months ago

Problematic SQL Sorting

Sometimes, all you want to do is a simple ORDER BY, but it just doesn't work. SQL has some quirks when trying to sort «text» numbers, especially when they are decimal numbers.

Consider the following Database table, myTable:

  1. Code  varchar(5)  | Descr varchar(100)
  2. ------------------|--------------------
  3. 1                 | Code 1
  4. 1.1               | Code 1 point 1
  5. 1.2               | Code 1 point 2
  6. 2                 | Code 2
  7. 3                 | Code 3
  8. 10                | Code 10
  9. 11                | Code 11
  10. 20                | Code 20

If you wanted to do a simply query to order by the Code field, one would think that a simple ORDER BY would do the trick.

  1. SELECT
  2.    Code
  3.   ,Descr
  4. FROM
  5.    myTable
  6. ORDER BY
  7.    Code ASC

Unfortunately, it doesn't. This produces:

  1. Code              | Descr          
  2. ------------------|--------------------
  3. 1                 | Code 1
  4. 1.1               | Code 1 point 1
  5. 1.2               | Code 1 point 2
  6. 10                | Code 10
  7. 11                | Code 11
  8. 2                 | Code 2
  9. 20                | Code 20
  10. 3                 | Code 3

In order for the DBMS to interpret the Code field as a Number, not as text, we need to CAST it to a numeric datatype, in this case i will use float.

  1. SELECT
  2.    cast(Code as float) AS 'Code'
  3.   ,Descr
  4. FROM
  5.    myTable
  6. ORDER BY
  7.    Code ASC

Yup, this doesn't work either. Suddenly you may find yourself with 1.999999999999 instead of your code 2. The rounding mechanism is not perfect. So, we need to take this a step further, and once again re-cast our float as a varchar. This will fix the rounding problem.

  1. SELECT
  2.    cast(cast(Code as float)as varchar) AS 'Code'
  3.   ,Descr
  4. FROM
  5.    myTable
  6. ORDER BY
  7.    Code ASC

The above will produce your results table nice and neat and perfectly sorted.

  1. Code              | Descr
  2. ------------------|--------------------
  3. 1                 | Code 1
  4. 1.1               | Code 1 point 1
  5. 1.2               | Code 1 point 2
  6. 2                 | Code 2
  7. 3                 | Code 3
  8. 10                | Code 10
  9. 11                | Code 11
  10. 20                | Code 20

Knowing how to work around the tweaks of any system will save you a lot of time and hair pulling. Fortunately, there are built in functions that make it easy on us developers, but sometimes finding them can be a little tricky.

This is the first of my SQL articles to come, so check back often for new articles and updates.

This code was tested for MSSQL Server 2000. Rounding quirks may react differently in your DBMS.

Like this article? Please Digg it

By Brian, 2 years and 3 months ago

Is it Time to Abandon 800x600?

Yesterday, May 15th 2006, Yahoo! Inc. released a link in their blog to a preview page of their new layout which perhaps may set the standard in pushing away from developing for 800x600 resolution. It will not fit without horizontal scrollbars at 800x600 resolution, but fits the screen nice and neatly with just a small padding around the edges in 1024x768. Frankly, I'm suprised to see them make the move to a fixed-width, non-fluid template.

The new left navigation menu is also very cutting edge «web 2.0». While still sorted in alphabetical order, it utilizes web 2.0-style «tags» in which the more popular items are in a larger font.

Will this release finally give the last push to totally abandon 800x600? I don't know if i'm quite ready for that yet. I for one know that both my parents in their early 50's use 800x600 on their 17» CRT, and they have a hard time seeing that sometimes, so I cannot imagine them moving to 1024x768. Perhaps, this will become the leading accesibility issue, perhaps it will have no effect. But I for one still believe in making sites fluid, or at the very least, not so wide as too force a horizontal scroll bar.


EDIT: 5/17/2006, 14:36 GMT -5

I think it is fitting that after nearly 20,000 views and 1500+ Digg's to this page, that i include the real-time image of the resolution stats visiting this page. While only 2% as of this writing are on 800x600, the results are skewed as us techies are more apt to have better equipment.

Pie Chart for Resolutions

← Previous 01 02 03 04 Next →