Codeworks client log in
latest tweet
@RobLoBue @applingua more important Coldplay are on BBC4!
Have a rummage around our archive = there's some real hidden treasures in there!

news, announcements & our blog...

Displaying all posts with the tag 'code-tip'

UI Inspiration for developers posted by Kevin S, 19.04.2012

UI: User interface. The means of communication between a person and some software. When designing an application, lots of question arise. How should it look? How easy is the interface to understand? What should the colour scheme and borders look like? I was having a conversation with a friend of mine recently who told me the secret to success is to give away your secrets and as it's my turn to write a blog I figured I'd give away some of my secrets!

First you need to take yourself away from the computer and sit down with a pencil and paper; even if you can't draw here's a little tip to help you get over your drawing fear. Lines. Draw a browser window on your piece of paper, but rather than draw a box, with each side of the box draw several lines on top of each other with quick strokes of the pencil. Sounds mental, but what you're trying to create here are ideas, and ideas come from sketches, and that's what you're creating.

Draw a basic layout of buttons, boxes and content suggestions with written titles inside the boxes. Being away from the computer will help you picture an innovative design inside your head. Draw down these ideas and if you come up witha few different ones then keep them. Who knows, maybe they will become handy later.

Once you have a general idea for the layout of your new software you'll need to head back onto the computer for interface inspiration and there're hundreds of websites which you can choose from. I like the websites with user submitted entries and one of my favourites is http://dribbble.com/ - its great because it only contains snippits of screenshots rather than the whole project which means you really do only take the inspiration from someone elses work rather than end up wripping it off.


Leave a Comment

Background imgs in Outlook, who knew! posted by Kevin S, 12.12.2011

I recently noticed a spout of emails coming into my inbox that have background images!? As many developers know background images in outlook are non existant, unheard of, a miricle!

So as any self respecting developer would do i jumped straight onto google with the string of keywords "when did outlook start supporting background images". Well, as it turns out a backround *image* does work, its background *images* that do not.

I came accross a blog that then explains that background images do not work in Outlook (thank goodness im not going crazy!) - but what will work is one single background image that sits in the body tag! There is one little snag that you will need to deal with (as if a Microsoft product would just work!). While every other client seems to gracefully assume no-repeat for the second part of the repeat line, Outlook does not. Take a look at the css code below and boom, you'll have body background images working.


body {
background-image: url('http://www.codeworks.org.uk/emails/bg.jpg');
background-repeat: repeat-y no-repeat;
background-position: top center;
background-color: #d9c092;
}

Leave a Comment

MySQL Insert or Update if exist posted by Kevin S, 03.03.2011

When developing applications its inevitable at some point you'll be checking to see if something exists and if it doesn't; creating it in the database.

The way you've most likely been doing this is running a select query to see if it exists, grabbing the ID if it does exist then executing an UPDATE or noting it doesn't exist then executing an INSERT. It's time consuming and adds more unnecessary code you feel you probably don't need.

We have an answer!

There is a way to run an update within MySQL and make a note as to how many records it has updated, you can check to see if this is zero then run the insert code if need be, simple eh? Check out my example below and start counting up those saved seconds for another tea and biscuit break!


MySQL Insert or Update if it exists

$result = mysql_query("UPDATE table SET notes = '' WHERE date = '$date'");
if (mysql_affected_rows() == 0) {
      $result = mysql_query("insert into table () values ();");
}


Leave a Comment

A coding tip: Javascript setTimeout posted by Kevin S, 02.03.2011

We're developing a lot of applications that require things to happen on the page without refreshing, we use the jQuery library to achieve a lot of the results we require but while all this stuff is happening on the page sometimes need animation or the action you're about to achieve to wait a second.

To achieve this you'd usually use the standard setTimeout function within Javascript.

It does the job perfectly, right down the very millisecond; however, if you're asking the timer to pass a variable to the function you're asking it to run after a certain amount of time you'll find it falls on its feet and passes nothing at all.

All you need is a 'closure', closures are arguably the great secret of Javascript: the way variable scope stacks get frozen at the point of closure (and hence variables persist within the closure) is quite subtle and catches most out, including me! See what im talking about in the examples below


This wont pass anything

diarymessages = setTimeout('messagereel(newid);',10000);



This will!

diarymessages = setTimeout(function(){messagereel(newid)},10000);


Leave a Comment

A coding tip: MySQL CASE posted by Adam B, 18.02.2011

Here's a top tip to speed up anyone's day (so long as they spend their days typing code). Sometimes you may want to have an on/off status for a particular entry in a database. For example, in our CMS system you can make web pages visible or invisible to the public by simply clicking the on/off button for each page. To do this might involve looking in the database, finding a field, checking the value and changing it accordingly (eg 1 for on, 0 for off).

So without the need for all these lines of PHP and MySQL you can simply use the MySQL 'CASE' construct, which looks at a field, and changes it if it is a certain value,  in much the same way as an if ... else statement (but with much less code!).

Have a look at the example below, this is a quick an easy way to say "If 'status' is set to 1, set it to 2, but if it is set to 2, set it to 1. And Bob's yer uncle!


MySQL CASE Construct

mysql_query("UPDATE tablename SET status =
       CASE status
       WHEN 1 THEN 2 WHEN 2 THEN 1
       END
       WHERE id='14'");

If you've got a tip, correction or comment regarding our coding tips, get in touch from the contact page!


Leave a Comment

A coding tip: The Alphabet posted by Adam B, 14.01.2011

In some projects you sometimes need to print out the alphabet either for a search facility or maybe because you like letters, either way we found a solution today which we thought was worthy of sharing!

In PHP, there are more than 700 built-in functions. The one function im going to be sharing with you today is called "range". The range() function creates an array containing a range of elements that can be returned from low to high.

This function is mostly used with numbers like this: $number = range(0,3); but it can also be used with letters $letters = range('a','e'); Take a look at our examples and outputs below.


PHP range() Function

$number = range(0,3); print_r($number);
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
)

$letters = range('a','d'); print_r($letters);
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
)

If you've got a tip, correction or comment regarding our coding tips, get in touch from the contact page!


Leave a Comment
« Previous Blogs