A common problem you may find when adding dates to mySQL is that mySQL date column have differing formats to what we humans like to read. This easy function makes the dates interchangable.

//sets $date as current date in familiar format.

$date = date('d-m-Y');

//swaps year and day around for insertion to database

$date = changeDate($date);

//The function goes anywhere on your page

function changeDate($date) {

// explode $date into an array seperated by the colon
$tempDate = explode('-',$date);
//change year and day around (eg 29-04-2010 will become 2010-04-29)
$date = $tempDate[2].'-'.$tempDate[1].'-'.$tempDate[0];

return $date;

}

?>

*using 1.3.12 beta version

This is a quick tutorial on how to record from an external device such as a tape cassette player or microphone and then save to a particular format.

1. There are certain ways to record from a device eg headphone socket to PC input or microphone socket or by co-axial to co-axial. Once your external device is setup then you need to tell windows or specifically Audacity what the record device is by opening a new Audacity project (File>New) and click Edit>Preferences>Devices. Here you’ll see your playback and record device options which you can change. All computers are different so you’ll need to experiment what are the right settings but playback shouldn’t need to be changed. If you’re using ‘line-in’ then you should see a line in option or at least your sound card displayed there.  See the example below (click to zoom in).

Audacity Preferences

Editing device settings in Audacity

2. Once you’ve setup the record device you can then press the record button to start recording (remember to start the cassette first). You should see the wave format being displayed as it records.

3. It’s important to get the volume level right on your external device. You want to optimize the level so it doesn’t go above zero DB at any point. Any sound that goes above this level cannot be processed by analogue speakers and will come out distorted. You also don’t want it to be too quiet as you’ll get more back ground hiss if the listener has to increase volume to hear it.

Recording in Audacity

Recording and Deleting in Audacity

4. Above shows the record button and viewing window. You can delete the recorded content by pressing the ‘x’ delete button.

5. You may need to edit the wave to tidy it up eg trim the start and ends. You should also normalize the wave by clicking Effect>Normalize. This increases or decreases the volume to the perfect setting (0db).

5. Once you’ve finished you can save your project by clicking ‘File>Save’.

6. You will then need to export your tune as MP3 or other familiar format by clicking File>Export. Then choosing a name and location for your file. See Below.

7. You may need in download the lame_enc.dll to convert to mp3. This can be found on their Audacity or Lame Library website.

Many people ask how you can alternate row colours in a table  when using multiple rows. The answer is simply to check whether the row loop is an even number or not using the modular symbol (%). In this case we’ll use PHP.

<table>

<?

for ($i = 0; $<50;$i++) {

if ($i % 2 == 0) {    echo ‘<tr bgcolor=”#f0e8f2″>’; } else { echo ‘<tr>’; } ?>

<td>my column</td>

</tr>

} ?>

</table>

This makes 50 rows and the command ($i % 2 ==0) asks if the variable is even and if so colour the background of the row. This technique becomes very handy when we don’t know exactly how many rows we are displaying. For example when loading in multiple rows from a database. The following example loads rows in from a mysql database. This code presumes you’re already connected to the database.

<?

$sql= “SELECT * FROM items”;

$result = mysql_query($sql) or die (mysql_error());

$i = 0;?>

<table>

<?
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){

if ($i++ % 2 == 0) {    echo ‘<tr bgcolor=”#f0e8f2″>’; } else { echo ‘<tr>’; } ?>

<td> <? $row['id']; ?> </td>

<td <? $row['name']; ?> </td>

</tr>

<? } ?>

</table>

Notice the slight change of code: if ($i++ % 2…

The variable $i is incremented (increased by one) automatically each loop. If you need to change the starting colour then simply change the 0 to a 1 so it asks if the number is odd.

This question gets asked alot but the answer is incredibly simple.  You treat the document as if it’s another webpage that is you ‘link’ to it and the browser will do the rest. Any file that is not recognised as a webpage by any browser is treated as a ‘download’ and will ask the user if this file should be ‘opened’ or ‘saved’. An example of this can be seen below.


linking to a document

Downloading a document using Firefox


This screenshot shows the option of opening the file straight away with the relavent program, in this case MS Office, or downloading directly on to the hard drive. This is done by simply coding this to your website:

<a href="http://myWebsite.com/myDocument.doc">Download this document here</a>

The same method can be used to download Adobe Acrobat Reader PDF (.pdf) files although with .pdf files most browsers will have a special plug-in that automatically opens the document without having to specify which program to use.

<a href="http://myWebsite.com/myDocument.pdf">Download this PDF document here</a>

Conditionals: The IF statement

In our first 2 chapters we looked at variables. This chapter we’ll look at conditionals.  Conditional statements in programs ask a question and much like human responses  will return a true or false. Combined with loops and variables they are incredibly powerful.

The conditional operator you will see in most computer languages is the ‘IF’ statement and the majority of languages simply use ‘IF’. Along with the IF statement are ‘comparison operators’. You will have seen these in maths: greater than, less than, equal to and so on.

Greater Than: >

Less Than: <

Equal To: = (sometimes == in some languages)

Equal To OR Greater Than: >=

Equal To OR Less Than: <=

Not Equal To: !=

Not: !

The ! signifies the opposite or negative. So:

if 6=7 returns false

if 6 != 7 returns true

When using the IF statement we need to tell the computer to do something if the return statement is true. For this we ususlly include brackets {}.

if 6<7{
print “6 is less than 7″
}

If the above statement is true then the computer will run the code within the brackets, if not then it will jump to the end bracket and continue from there.
We can also tell the computer to do something if the statement is false or even ask another question within the same conditional.

if 6>7{
print “6 is greater than 7″
}
else if 6==7 {
print “6 is equal to 7″
}
else {
print “6 is less than 7″
}

The above code asks if 6 is greater than 7 (false move to next question) is 6 equal to 7 (false again move to next) else means simply means if the above aren’t true run these brackets. Below is a good example when you’ll need an else:

if pinEntered = accountPin {
print “Your account balance is £” + balance
}
else {
print “Pin entered is wrong”
}

Above you saw an example where a pin entered is checked and two different scenarios can occur. This also is the first example you’ve seen where variables are used in the IF statement. The pinEntered and accountPin are variables, most likely in this case to be integer variables. The balance variable would have been a decimal variable.
Conditional statements can also include strings and other variables. Many languages also wrap the statement in brackets for easier reading.

string nameEntered = “John”

if (nameEntered == “John”) {
print “Hello John”
}

but you must follow variable ‘type’ rules when using statements

int nameEntered = 1

if (nameEntered == “1″) {

print “Hello Number 1″

}

Output: Error type mismatch

The above statement should have been if (nameEntered == 1). The quotations indicate the variable is a string.

Next chapter we’ll look at the IF statement and other conditionals in greater depth.

There has been widespread criticism of Italy’s ruling to convict Google executives for their ‘role’ in displaying a gruesome video on the Google Videos website that was uploaded by a registered user in 2006. The executives were given six month suspended sentences even though Google removed the video after first initial complaints and that the accused had absolutely no knowledge of the video or what is was until after the event.  If the ruling is held then it will have massive repercussions on the Internet in Italy and possibly the rest of the world as it essentially enforces mass censorship of what service providers can display.

Service providers including those in the EU are protected by law providing they remove any illegal film or act when the relevant authorities ask. This ruling is simply against EU law and is likely to have been heavily influenced by Prime Minister Berlusconi who has strong opinions about the censorship of the Internet.

Italy is not the only government that is demanding changes to the Internet. China is well known to have widespread censorship of the Internet, Australia recently have put forward plans to ‘filter’ the Internet and the UK Labour government may soon be taxing the Internet.

Variables

We took a brief look earlier about variables and printing them. This chapter concentrates on manipulating them and variable types.

You can change a variable by simply putting:

Set apples to 3 or
apples = 3

But what happens when we want to add, subtract, divide or multiply the number stored?

Add 4 to apples or
apples = apples +4

The pseudo code here is pretty self explanitory but the standard code states that: take the number in apples and add 4. Print apples will now output 7. The same can be applied to subtraction and others:

apples =4
apples = apples – 2
apples = apples * 4
apples = apples / 8

print apples

Output > 1

The code above subtracts 2 from the original 4, multiples by 4 then divides by 8 leaving 1. You can make these equations as complex as you like but it’s important to remember computers use standard maths rules and will multiply and divide numbers first, so always use brackets when possible.

If 3 people have 2 apples and each person buys another 2. How many apples are there in total?

What’s the answer? 12

Did you get this using 2+2*3?

2 + 2 * 3  is not 12

2 + 2 * 3 = 8    —–> CORRECT

The computer will multiply first so writing this is identical to writing 2+(2*3). You therefore need to bracket the 2+2.

(2 + 2) * 3

So written in code would look something like:

apples = 2
people = 3

print (apples + 2) * people

Output > 12

If you left out the brackets the output would be 8.

Variable Types

So far we’ve only looked at whole numbers but what happens if we want decimal numbers and what would happen if we put a word in the apples variable?

Here we’ll look at an important part of variables which is variable type. Variable types come in many forms with the most common being integer, doubles and strings.

Integer: Usually shortened to ‘int’. An integer is a whole number. Integer variables cannot have decimal places eg -5, 3, 3276.

Double: Doubles are the usually the largest variable type in terms of bits they can store. They are used to store decimal numbers eg 5.34, -100.5678, 400012.87266723.

String: A string variable holds words and letters. They usually cannot be manipulated in the same way ints and doubles can unless converted but are excellent at storing any string of characters without error.

As we mentioned in Chapter 1 you declare and initialise variables. How you do this depends on the langauge you’re programming in. You cannot mix variable types and so the example below would throw an error. Shows psuedo code followed by standard code.

Set apples as integer equal to 3

Set apples to 4.5

Output > Error cannot add double to integer

or

int apples = 3

apples = 4.5

Output > Error type mismatch

The ‘error type mismatch’ is an error output shown on many langauges and will usually point to apples=3.5. Variable types are usually the one thing most beginners struggle to get to grips with especially when equations mix types. You can convert variable types by typecasting a variable. ‘Typecasting’ is when you convert a variable to a format you want. If we look at the example above again:

Set apples as integer equal to 3

Convert 4.5 to integer and set apples to this number.

or

int apples = 3

apples = convertToInteger(4.5)

The output now would be 4.5? No

Even though this typecasting doesn’t return an error, you’re converting the number to an integer that cannot have decimal places. So in the majority of cases the computer simply removes all numbers after the decimal point therefore printing this variable would output 4.

I bet you’re wondering if you can convert a string? No probably not but you can on some languages if the string is a number.

int apples = 3

string oranges = “6″

string name = “mark”

apples = apples + convertToInteger(name)   > error thrown

apples = apples + convertToInteger(oranges)

print apples

Output> 9

In many languages the typecast is simply written: apples = apples + (int) oranges

This concludes out tutorial on variables. Next week we’ll look at sequences, conditionals and iteration.

Computer programming, coding and languages come in all shapes and form but like human languages they all have a common structure much like nouns, verbs and adverbs.  Once you learn programming skills and the fundamentals behind it you can generally pick up most langauges relatively easily. We could go on forever about the theory of programming languages but form here we’ll just jump right on in. For these tutorials I will write in psuedo code (PS) and also standard coding (SC). The standard coding is in no particular language but will resemble most modern langauges like Java, C++, C#, PHP or Python. Please bear in mind that the coding may differ from language to language.

In the next few sections we’ll look at the 4 basics of programming: Variables, Sequence, Conditional and Iteration. They may sound complicated but once you use them you’ll find the logic behind them incredibly simple to use. Today we’ll look at variables.

It’s likely you’ve heard of variables before if you’ve spent anytime around computers. They are essentially storage containers: they store numbers or letters within the computers memory. Exactly how this process works is unimportant for now, all we need to know is how to store something and retrieve it.

Variables should be written lowercase with the first letter capitalised if using more than more word. They also should describe what the variable is doing or what it relates to so coders can get a fair idea what it does. For example:

Right:

apples

applesAmount

amountOfApples

Wrong:

Apples

appleamount (not wrong but difficult to read)

ppp (again not wrong but meaningless)



Some variables are written all uppercase but we’ll look at those types another time.

To make a variable we usually have to declare and initialise it:

Set apples equal to 1 (pseudo code) or
apples = 1 (standard code)

This sets the variable apples to 1 and can be changed at any time. Notice the use of the ‘=’. In computing this can mean ‘set’ or ‘make equal to’ as well as ‘equals’. Yes it’s confusing and some languages make it more confusing by making ‘==’ mean ‘equals’. Bear this in mind when using the equals sign.

Set apples to 2 (pseudo code) or
apples = 2 (standard code)

You can print a variable to screen easily in most languages. This will print ’2′ on the screen.

Print apples or
echo apples
Output > 2

What can we store in a variable?

You can store anything you like in a variable like numbers, letters, words and references to other programmes in memory. The most common use is for numbers and words. When words are held in variables they are called ‘strings’ and they work in a similar way to numbers except they usually will require quotations to signify they’re strings.

Set names to “mark” or
names = “mark”

Printing the string usually works in exactly the same way as numbers.

Print names  or

echo names

Output > mark

So you can now do:

Print names and apples  or

echo names +”:” + apples

Output > mark:2

Notice how you can add your own strings within two variables, in this case the “:”

So far we’ve seen we can print variables but variables can also be manipulated with basic or complex maths. Our next chapter looks at manipulating variables and varible types.

Lower Merion School in the US have been issued with a lawsuit after remotely activating web cameras on laptops given to students for their work while at home. The shocking discovery came after a student was told off my a teacher for misbehaving at home while on the laptop.  The school claimed the remote access was for security purposes only in case the laptops got stolen but clearly they hadn’t thought it though properly. Still images could be taken of student minors and also other family members possibly in state of undress. Not only that but there are major implications if the software used for remote access was to be hacked. Hackers could potentially gain access to thousands of students laptops remotely.

Surely a more efficient and effective alternative would be to have background service software that could connect to a server remotely logging IP address? It’s something the software companies have used for years to find out who you are and what’s on your computer so why not schools as well?

Windows updates will soon give the option of which browsers a person would like installed on their computer. After pressure from the EU Microsoft have agreed to make their Internet Explorer uninstallable and will offer a choice of the most popular browsers.

IE8

Although this is a welcome step for fair competition it may cause some problems with accessing the Internet if users select only one browser. It’s recommended to always have at least two browsers installed on your computer. It’s not uncommon for a particular browser not to work on a particular website while another does. Google Chrome and Mozilla Firefox have both been in the press lately with issues about compatibility on some sites.