Blogvaria

This page is brought to you by Blogvaria (http://blog.evaria.com).

To obtain more information, ask questions and interact please visit our website.

Back to Blogvaria landing page
Feedback
Subscribe
   
Blogvaria

 

The personal pages

Archive for Programming

Finding duplicate entries in MySQL

From time to time I need to check for duplicate entries in my databases. E.g. when I have large numbers of clients signing up for events or similar.

I know there’s ways of deleting multiple entries but sometimes I just need to find out WHO and HOW MANY. The following simple query does just that:

SELECT the_field_name, count(*) AS n FROM the_table GROUP BY the_field_name HAVING n>1;

Hope this proves useful for some of you having the same “problem”.

Should you just wish to remove any duplicate entries then take a look at Justin Cook’s article on the subject.

Filed under Programming | Comments off

Working with linked tables

I’m currently working on a website project that requires separate websites (different language dependant domains) to share a common image database. Thus, to avoid having to upload and link in the images for each individual website, I’ve decided to use data queries that take advantage of linked tables. The only main criteria are to have a common unique ID in order for the queries to work properly and all tables residing in the same database (which requires that you are able to make cross domain queries).

In my case I’m defining a unique page reference number for each “product page”, which obviously is the same for each individual language specific website, and an equal reference number for each image or image group. An example of a query/join statement that could “grab” your images could look like:

SELECT imageDB.filename, imageDB.filepath, websitePages.id
FROM imageDB, websitePages
WHERE imageDB.ref_number = websitePages.ref_number;

If you for some reason get a syntax error you could rewrite the statement as follows according to the ANSI SQL-92 syntax specification:

SELECT imageDB.filename, imageDB.filepath, websitePages.id
FROM imageDB INNER JOIN websitePages
ON imageDB.ref_number = websitePages.ref_number;

Note! The image table is named imageDB and the website table is named websitePages

The result gives you the name and path for your image related to a specific page/product. Quite useful isn’t it!?

More simple tips and online tutorials can be found e.g. here.

Filed under Programming | Comments off

Using PHP to print only the first sentence

Ever wanted to pull just the first sentence of a text and print it? If yes, this is for you.

Simply add the following code (in PHP) to your page/system before the actual HTML stuff begins:

< ?php
function getFirstSentence($string)
{
    // First remove unwanted spaces - not needed really
    $string = str_replace(" .",".",$string);
    $string = str_replace(" ?","?",$string);
    $string = str_replace(" !","!",$string);
    // Find periods, exclamation- or questionmarks with a word before but not after.
    // Perfect if you only need/want to return the first sentence of a paragraph.
    preg_match('/^.*[^\s](\.|\?|\!)/U', $string, $match);
    return $match[0];
} 
?>

Then call the function somewhere on the page where you want the text to appear:

< ?php
    // The $string below could/should be a text string pulled from your database or similar
    $string = "Lentence oneasdasd asd asd asdasd, ?. Sentence two? Sentence three! Sentence four.";
    echo getFirstSentence($string);
?>

Comes in handy for search result pages, page titles and similar listings.

Filed under Programming | Comments off

How to remove the active/focus borders

I’m sure you have noticed that when you click a hyper link, and especially a linked image, a dotted border appears around it. Have a look at CSSplay for more examples and proper CSS code fix related to this.

A few quick solutions

For those of us using the jQuery Java framework the “solution” is incredibly simple. Just call the following function in your header and all dotted borders are gone:

jQuery("a").focus(function(){this.blur()});

Using CSS it’s almost as simple (at least for all browsers except IE):

a:focus {outline-style: none;} 

Using basic JavaScript the following should do the trick:

for(var i=0;elm=document.links[i];i++)
{
elm.onfocus=function(){elm.blur();};
}

Some would probably say that this shouldn’t be done because the active/focus dotted border is there to show visitors who are using tabbed link selection which link is selected. But when we are using CSS we can style our own active/focus state and in this case the dotted border is not so necessary. I’ll appreciate your take on this as I’ve debated this “issue” with some of my clients on several occasions.

Filed under CSS & Design, Programming | Comments off

Introducing SWFObject v2

SWFObject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file. I’ve previously mentioned SWFObject in one of my posts last year.

The latest release is now featured on Google code, and from my initial testing it appears to be flawless.

Filed under Programming | Comments off


Page 1 of 1312345678»...Last »

Quick links - Blogvaria time links [ sitemap ]

2012 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2011 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2010 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2009 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2008 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2007 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

2006 | Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec

Akismet has protected Blogvaria from 122,261 spam comments. Design by Evaria.com. Powered by WordPress.
Our beloved and trusted server has rendered 2.785 pages so far today, an amazing 1.900 pages yesterday
and even more astonishingly 938.897 pages since 19 Feb 2012 alone without dropping a byte nor a pixel.

Close
E-mail It