RedCoupe

Order by date when stored as a nvarchar

by on Jul.21, 2011, under Web design / development

Just had a MS SQL Server problem where as the title suggests, I wanted to order a query by a date column to show the most recent entry at the top, but it wasn’t working because the date column was stored as a nvarchar instead of a datetime.

I tried various things like CONVERT…. and CAST…AS datetime, but for whatever reason I could not get this to work.

I got round this by doing some string concatenation:

SELECT * FROM tbl_articles
WHERE visible = 1
ORDER BY RIGHT(dateval,4)+SUBSTRING(dateval, 4, 2)+LEFT(dateval,2) ASC

The date was stored in the table as text like 22/10/2011, the above concatenating turns it into 20111022 which can easily be sorted in the proper order.

I know this is more than likely not the best way of doing it and should have persevered with the casts and converts but it works fine for the minimal amount of data I have in that table. No doubt I’ll have to revisit this if the number of records significantly increases.

Leave a Comment more...

Modified styles in WordPress

by on Jul.14, 2011, under Web design / development

I have another site produced with WordPress and it uses a modified version of the Twenty Eleven theme.

The trouble was that whenever I applied an update to the theme, it obviously overwrote my modified style.css. I suppose if I wasn’t lazy I could have copied the theme to a new folder and simply used the copied theme. Although I do like getting updates including any improvement tweaks etc.

To get round this I found a great plugin called Style Press which was made by grandslambert who has also produced some other handy plugins. So I installed it, added my custom css, reverted the style.css back to the original version, and it worked perfectly. So in future whenever I apply a new update to this theme, unless class or id names change, the site will always look the same because the extra bit of css is always added at the end of all the other style includes in the html.

Leave a Comment more...

Typing umlauts on an English language keyboard

by on Jun.30, 2011, under Web design / development

I’ve had reason to write a title in German that contains umlauts and apart from copying and pasting, I couldnt find a way to do this via my keyboard. By the way I’m using Windows XP.

I know I can use the “Character Map” application under Start>All Programs>Accessories>System Tools>

I found the ü symbol and it said the keystroke was Alt+0252. Well I tried this using the number keys along the top of my keyboard and it didn’t work. So I ended up just selecting what I needed and copying it etc. Since then I found out that if I took numlock off and used that number keypad it works fine.

Aparently on the Mac if you press Alt+u and then typing the following letter; a, u, or o. When the letter is pressed it will display the unlauts over the top as they should be.

Here’s a table of ALT codes for letters with accents:

UppercaseLowercase
Alt CodesSymbolDescriptionAlt CodesSymbolDescription
Alt 0192ÀA graveAlt 0224àa grave
Alt 0193ÁA acuteAlt 0225áa acute
Alt 0194ÂA circumflexAlt 0226âa circumflex
Alt 0195ÃA tildeAlt 0227ãa tilde
Alt 0196ÄA umlautAlt 0228äa umlaut
Alt 0199ÇC cedillaAlt 0231çc cedilla
Alt 0200ÈE graveAlt 0232èe grave
Alt 0201ÉE acuteAlt 0233ée acute
Alt 0202ÊE circumflexAlt 0234êe circumflex
Alt 0203ËE umlautAlt 0235ëe umlaut
Alt 0204ÌI graveAlt 0236ìi grave
Alt 0205ÍI acuteAlt 0237íi acute
Alt 0206ÎI circumflexAlt 0238îi circumflex
Alt 0207ÏI umlautAlt 0239ïi umlaut
Alt 165ÑN tildeAlt 164ñn tilde
Alt 0210ÒO graveAlt 0242òo grave
Alt 0211ÓO acuteAlt 0243óo acute
Alt 0212ÔO circumflexAlt 0244ôo circumflex
Alt 0213ÕO tildeAlt 0245õo tilde
Alt 0214ÖO umlautAlt 0246öo umlaut
Alt 0138ŠS caronAlt 0154šs caron
Alt 0218ÚU acuteAlt 0249ùu grave
Alt 0219ÛU circumflexAlt 0250úu acute
Alt 0220ÜU umlautAlt 0251ûu circumflex
Alt 0217ÙU graveAlt 0252üu umlaut
Alt 0221ÝY acuteAlt 0253ýy acute
Alt 0159ŸY umlautAlt 0255ÿy umlaut
Alt 0142ŽZ caronAlt 0158žz caron
Leave a Comment more...

Vi / Vim Shortcuts

by on Jun.15, 2011, under Web design / development

Im always forgetting the very useful vi shortcuts, so here’s a list of them:

ˆ = Control key

If you see a 10, this can be replaced by any number

OperationKeys
Return to Command mode from Insert, overwrite or append modeEscape
Enter Insert modei
Enter overwRite modeR
Enter append modea
Enter append mode at end of this lineA
Enter Insert mode on a new line after thiso
Enter Insert mode on a new line before thisO
Delete this word and enter Insert mode herecw
Delete this line and enter Insert mode herecc
Delete the next 10 lines and enter Insert mode here10cc
Move cursor left one characterleft arrow or h
Move cursor left e.g. 10 characters10h
Move cursor down one linedown arrow or j
Move cursor down 10 lines10j
Move cursor up one lineup arrow or k
Move cursor right one characterright arrow or l
Save this file and continue:w
Save this file and exit:wq
Abort without saving changes to this file:q!
Quit (no changes made):q
Save as a new file “new-file”:w new-file
Load the file “myfile” into vi:e myfile
Delete the character under the cursorx or Del
Delete the current word (inc. space)dw
Delete the next 10 words10dw
Delete the current linedd
Delete the next 10 lines10dd
Delete rest of this line, right of the cursord$
Yank the current line onto the clipboardyy
Yank the current word onto the clipboardyw
Paste the clipboardp
Undou
Redo^r
Jump to the bottom of the fileG
Jump to e.g. the tenth line of the file10G
Jump to the top of the filegg
Jump one page forward^f
Jump half a page forward^u
Jump one page back^b
Jump half a page back^d
Search for text from cursor/text
Find next occurrence of textn
Find previous occurrence of textN
Start of next wordw
End of next worde
Start of the tenth word forward10w
Start of next sentence)
Start of previous sentence(
Start of line0 (zero)
End of line$
Top of screenH
Bottom of screenL
Middle of screenM
Leave a Comment more...

Welcome back PSN

by on Jun.09, 2011, under PS3

For the ‘Welcome Back’ package I’ve gone for WipeOut HD (with Fury pack) and Infamous, for the PSP I’ll probably go for Little Big Planet and ModNation Racers. As a Playstation Plus subscriber I was pleased to be able to download Burnout Paradise as a freebie, nice one.

Leave a Comment more...

Get dropdown list label value

by on Jun.09, 2011, under Web design / development

I was working on a couple of web pages this morning to allow completion of a course booking form, user then submits to a thankyou page, confirmation emails are sent etc.

The problem I faced was that only the course ID was being passed to the thankyou page so in the emails that are generated, it displays Course Details: 7 , instead of Course Details: 12/12/2011 PHP Basics.

So my initial thought was to create a hidden field just before the end form tag together with some javascript that gets the relevant label value:

document.getElementById('coursedetails').value = document.getElementById('training_id')[document.getElementById('training_id').selectedIndex].innerHTML;

Then in the thankyou page I just got Request.Form(“coursedetails”), this is in ASP VBScript just in case you were wondering. Works like a charm.

Since doing this is I should have done it a much easier way and not have to rely on JavaScript being enabled. I already had the value because I was already using it to display the dropdown list label. So the hidden field could have just contained the default value of the currently selected item.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!