Archive for the 'Snippets' Category

18th Apr 2007

CSS Hacks (for IE 7, IE 6, Opera, etc)

The following CSS selectors are considered workarounds and hacks for specific web browsers.

IE 6 and below
* html {}
IE 7 and below
*:first-child+html {} * html {}
IE 7 only
*:first-child+html {}
IE 7 and modern browsers only
html>body {}
Modern browsers only (not IE 7)
html>/**/body {}
Recent Opera versions 9 and below
html:first-child {}

Source: CSS Hacks

Usage
If you want to add 5px padding to a div element called #comments specifically for IE 7, then you can use the following hack:

*:first-child+html #comments {
padding: 5px;
}

But if you want to apply the padding just for IE 6, then the following will do the trick:

* html #comments {
padding: 5px;
}

Note that CSS Hacks are not recommended due to their dependence on browser bugs and therefore they should only be used as the last resort.

A more comprehensive article on CSS Hacks can be found here.

Technorati Tags: , , , , ,

Posted in Snippets, CSS | No Comments »

02nd Mar 2007

LEFT JOIN and RIGHT JOIN in mysql

Use LEFT JOIN when you want to return all rows from left table regardless of whether they have any associated rows on right table.

Use RIGHT JOIN when you want to return all rows from right table regardless of whether they have any associated rows on left table.

SELECT
  users.`firstname`,
  pets.`nickname`
FROM `users`
LEFT JOIN `pets`
ON users.`id` = pets.`user`";

The above query will return all rows in users table regardless of whether they have any pets associated with them or not.

Technorati Tags: , , , ,

Posted in Snippets, PHP, Random | No Comments »

01st Mar 2007

Search engine friendly WordPress titles

This blog’s title (have a look in the title bar ^) has been seo-ed to the max. Here’s what I put in header.php of my current theme.

<title>
    <?php wp_title($sep = '');?>
    <?php if (is_home()) { bloginfo('description'); } ?>
     - <?php bloginfo('name'); ?>
</title>

Robert thinks it’s cool! What about you?

[Edit]

Here’s yet better version from Robert.

<title>
    <?php if (is_home()) { bloginfo('description'); } ?>
    <?php if (is_search()) { _e('Search Results' .
        ' for ' . get_query_var('s')); } ?>
    <?php wp_title($sep = '');?> - <?php bloginfo('name'); ?>
</title>

Technorati Tags: , , ,

Posted in Search, Snippets, WordPress | 3 Comments »

26th Feb 2007

Remove the first character in mysql

UPDATE `tablename`
SET `columnname` =
TRIM(LEADING  'THE CHARACTER YOU WANT TO REMOVE, eg: A'  FROM `columnname`);
TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] str)

Returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr is optional and, if not specified, spaces are removed.

mysql> SELECT TRIM('  bar   ');
        -> 'bar'
mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
        -> 'barxxx'
mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
        -> 'bar'
mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
        -> 'barx'

This function is multi-byte safe.

Source: MySQL 5.0 Reference Manual

Posted in Snippets | No Comments »

14th Nov 2006

New-Window Links in a Standards-Compliant World

function externalLinks() {

if (!document.getElementsByTagName) return;

var anchors = document.getElementsByTagName(”a”);

for (var i=0; i<anchors.length; i++) {

var anchor = anchors[i];

if (anchor.getAttribute(”href”) &&

anchor.getAttribute(”rel”) == “external”)

anchor.target = “_blank”;

}

}

window.onload = externalLinks;

Source: Sitepoint

Posted in Snippets | No Comments »

Free Anonymous Proxy