Thursday, March 31, 2011

Finding Duplicates with SQL

For finding duplicate:

SELECT [colName],
COUNT([colName]) AS NumOccurrences
FROM TableName
GROUP BY [colName]
HAVING ( COUNT([colName]) > 1 )


For finding rows that occur exactly once:

SELECT [colName]
FROM TableName
GROUP BY [colName]
HAVING ( COUNT([colName]) = 1)

Sunday, March 27, 2011

Placing text over image using CSS

<html>

<head>

<title></title>

</head>

<body>

<div id="main">

<div><img src="yourImage.jpg" /></div>

<div style="position: absolute; left: 20px; top: 160px;">

<span style="font-weight: bold; color: #fff;">Text Here...</span>

</div>

</div>

</body>

</html>

Thursday, March 17, 2011

Specific HTML strip Method in Php


<?php
function strip_only($str, $tags) {
    if(!is_array($tags)) {
        $tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
        if(end($tags) == '') array_pop($tags);
    }
    foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
    return $str;
}

$str = '<p style="text-align:center">Paragraph</p><strong>Bold</strong><br/><span style="color:red">Red</span><h1>Header</h1>';

echo strip_only($str, array('p', 'h1'));
echo strip_only($str, '<p><h1>');
?>

Output:
Paragraph<strong>Bold</strong><br/><span style="color:red">Red</span>Header