November 30, 2009

Convert decimal places without rounding

Category: Blog,PHP, khadlock at 1:13 pm

Here’s a quick way to set the number of decimal places to 2 in PHP without rounding a number.

floor($decimal*100)/100

 

November 19, 2009

Remove all select options with JavaScript

Category: Blog,JavaScript, Tags: , khadlock at 1:23 pm

Here’s a quick function to remove all select options using JavaScript.

function RemoveAllOptions(selector)
{
     while(selector.hasChildNodes()) selector.removeChild(selector.childNodes[0]);
}

 

November 17, 2009

MySQL REGEXP: where first letter is numeric

Category: Blog,MySQL, Tags: , , khadlock at 11:58 am

Get MySQL results where the first letter is numeric:

SELECT * FROM table WHERE (LEFT(columnname,1) REGEXP '[0-9]')
Or get MySQL results where the first letter is alpha:
SELECT * FROM table WHERE (LEFT(columnname,1) REGEXP '[a-z]')

 

November 15, 2009

Using the IN statement to retrieve multiple results from a subquery

Category: Blog,MySQL, Tags: , khadlock at 8:20 pm

Use the IN statement to retrieve multiple results from a subquery.

SELECT * FROM table WHERE id IN ( SELECT DISTINCT id FROM table WHERE id=1 )

 

November 14, 2009

Get MySQL results by first letter

Category: Blog,MySQL, Tags: , khadlock at 7:20 pm

The following SQL selects all the rows where columnname starts with the letter A, switch the letter or make it a variable and get the results you need.

SELECT * FROM table WHERE columnname LIKE 'A%'

 

November 13, 2009

Convert GET and POST to objects

Category: Blog,PHP, Tags: , , khadlock at 1:51 pm

Here’s a quick way to convert GET and POST arrays to objects with PHP:

$get = (object)$_GET;
echo $get->sample;
$post = (object)$_POST;
echo $post->sample;
In this case the “sample” property would be an array key.

 

Submit an Inquiry for your project

Category: Blog,Studio Sedition, khadlock at 11:32 am

You can now submit an inquiry for your web project at http://www.studiosedition.com/inquire

 

Setting the label “for” attribute with JavaScript

Category: Blog,HTML,JavaScript, Tags: , , khadlock at 10:53 am

Sometimes JavaScript offers unique names for element attributes, for example, CSS properties with words that are normally separated with dashes are camel case in JavaScript. The label element’s “for” attribute is no exception, in fact it’s probably the most unique one I’ve stumbled across, which is why I thought it was important to share. When you set the label “for” attribute with JavaScript you have to set it as “htmlFor” and of course give it the same value as the input element’s id that you are tying it to.

 

November 6, 2009

The imagetoolbar meta tag

Category: Blog,HTML, Tags: , , khadlock at 12:24 pm

Here’s an oldie, but a goodie. Remove the pop-up that appears over images in Internet Explorer 6:

 

November 5, 2009

Twitter’s API whitelist

Category: Blog,BlogToTweet,Twitter, Tags: , , khadlock at 2:27 pm

One of our product’s BlogToTweet.com has been approved for the Twitter API whitelist, meaning any rate limits no longer apply to authenticated requests made through BlogToTweet. This was never an issue, but our user base is quickly growing, so we were proactive in achieving whitelist status to prevent any problems from creeping up for our users. If you use the Twitter API and are wondering how to get approved for the Twitter API whitelist, visit http://twitter.com/help/request_whitelisting To learn more about BlogToTweet you can visit our product page at http://www.studiosedition.com/product/BlogToTweet

 

November 3, 2009

decompress gz with php

Category: Blog,PHP, Tags: , , , , khadlock at 9:14 pm

I had a lot of trouble getting zlib to work today with PHP on our Media Temple DV server, but after a lot of testing discovered an easy solution to decompressing/unzipping .gz files.

exec("gunzip Filename.gz", $results);
Once decompressed I can read the file contents using fopen, file_get_contents, etc. More information on the gzip commands can be found at http://en.wikipedia.org/wiki/Gzip

 

November 2, 2009

Remove empty array values in PHP

Category: Blog,PHP, Tags: , khadlock at 7:51 pm

Here’s a super easy way to remove empty values from an array in PHP:

$a = array_diff($a, array(""));
In a recent project we were reading in a text file and creating an array based on each new line, so we used the same method to remove any new lines that were empty.
$a = array_diff($a, array("\n"));

 

Custom CSS Signatures

Category: Blog,CSS, Tags: , , , khadlock at 2:52 pm

I feel that any form of branding is important, especially when it comes to sending emails. Think about it, how many emails do you send a day? This post has been around for a while, but I often refer to it when designing a new email signature and thought it was worth sharing: http://allforces.com/2006/04/14/css-signatures/ It’s so easy to follow if you use Apple Mail. Here’s the new one I’m using based on this article: http://www.studiosedition.com/branding/email-signature.html