Custom ordering by a list of values

There are times when I needed the results returned from mysql returned in a specific order. An example would be when I have a list of ids for which I need the rest of the information from mysql (not doing a query for each of the ids) but preserving the order in which my . . . → Read More: Custom ordering by a list of values

Substr without cutting words

Very often we need to display only the beginning of a larger text and for this we have substr() function. But we would like to do that without cutting any words (think of poorly truncated words like “butterfly” or “assassin”).

This is a very quick fix for the above problem:

1 2 3 4 . . . → Read More: Substr without cutting words

Very simple database structure for a tag cloud

The tag cloud (or word cloud) is a visual representation of the word content of a given text: in plain English it’s a listing of the words having different sizes, those used more frequently being larger and those less used being smaller. It started out as a buzzword but quickly become largely used. I . . . → Read More: Very simple database structure for a tag cloud

Types of functions in MySQL

MySQL supports two very distinct type of functions: regular functions (some may also call them scalar functions) and aggregate functions which is often used in conjunction with GROUP BY statement (in fact a statement containing no GROUP BY clause is equivalent to grouping on all rows). The difference between the two types is that . . . → Read More: Types of functions in MySQL

Computing an array’s average

Needing to calculate an array’s (composed of numeric values) average, I used the following function:

1 2 3 4 function array_average($a) { return array_sum($a) / sizeof($a); }

Categories

Archives

Calendar

June 2010
M T W T F S S
    Jul »
 123456
78910111213
14151617181920
21222324252627
282930