Thursday 6 September 2012

Brand new HTML and PHP Tutorial

Hi all

You can find a brand new tutorial website specifically for HTML and PHP development. It's in its early stages at the moment but you can find it at TeachMe.webege.com It covers HTML basics, CSS and PHP. You'll learn all about loops, arrays, design and much more.

Come check it out now at TeachMe.webege.com

Monday 2 July 2012

All about PHP loops

So maybe you read my last post about arrays here, or maybe not. If you want a quick catch up or to learn something new check it out.

Quick recap. I'm a web developer at Computer Related. And I love web developing.

This post is about loops in PHP, it's not designed to be a be all you need post, but more of a reminder or a basic lesson to get you going.


I have many more tutorials and self help pages over at teachme.webege.com.


What is a loop?

A loop is exactly what it sounds like, something going around and around. For our purpose a loop is something that gets executed over and over again


Why do I need a loop

If you want to do anything more than once then more than likely you need a loop of some kind (not all the time).


Types of loops

In PHP we have four type of loops. We have a FOR loop, FOREACH loop, WHILE loop and a DO WHILE loop

.

How do I know which one to use

Once you understand the principles of a loop you'll know, which we'll go through next.


The principles

Imagine the scenario below

I want to print 10 numbers on seperate lines to the screen. And I may want to change that to 100 in the future.

You could just write 10 numbers in html, and if needed write another 90. But what if we then wanted 1000, this becomes more tedious. Sounds like a loop is needed.

What about if I created a loop that went round the amount of times i wanted, and each time it printed out a number to the screen. Now something like this could work with any amount of numbers.

Ok, lets do it.


for(i = 1; i <= 10; i++){
 echo i."/n";
}

Output =
1
2
3
4
5
6
7
8
9
10


i=1;
while(i <= 10){
 echo i."/n";
    i++;
}

Output =
1
2
3
4
5
6
7
8
9
10


do{
 i=1;
 echo i."/n";
    i++;
}while(i <= 10);

Output =
1
2
3
4
5
6
7
8
9
10

OK. So some of you may be thinking what the *, and some may be thinking i remember this. Let's get us all on the same page.

For a start, the above code is correct other that instead of '$i' i have used 'i' so it reads easier. 'echo' simply means write out the line, '/n' means start a new line.

Notice in all the loops 'i' is the index, and we use this to count how many times the loop has gone round. We also need to tell the loop to stop at some point, that is what the '10' is doing, it says once 'i' is equal to 10 stop the loop. The important thing to notice here is that we could change the '10' to '100', '1000' or what ever we like. See how the loop makes life simpler. Another thing to notice in all the loops is the fact that 'i' needs to be incremented, 'i++' increments 'i' by 1, or in lay terms adds 1 to 'i'.

So there we have the basics needed for a loop, a start number, a max number and a way to increment start number.

So what's the difference

Not much between a 'while' loop and a 'for' loop other than syntax. The 'for' loop initialises all its variables and conditions within the 'for' statement, whereas the 'while' loop only states the condition, the variables are initialised outside of the 'while' loop and incremented within.

The 'do while' loop and 'while' loop differ only slightly, the 'while' loop checks the loop conditions before entering the loop, whereas the 'do while' loop checks the loop conditions at the end of the loop. So in the examples above if i say that 'i = 11' then in the 'while' loop nothing is printed as it checked if 'i' was equal too or less than '10', whereas in the 'do while' loop it would print '11' because 'i' is checked after the echo statement.

What's the fourth loop type you mentioned?

Glad your still here and concentrating. The 'foreach' loop is specifically used for arrays, not to say the the others can't be used for arrays.

The 'foreach' loop is like the 'for' loop but all we need to declare is the array to loop and the output variable, see below to understand.


$array = array(1, 2, 3);

foreach( $array AS $number){
 echo "Number: $number /n";
}

output =
Number: 1
Number: 2
Number: 3

If i where to do the above using a 'for' loop it would look like below


array = array(1, 2, 3);
num = count(array);
for( i = 1; i <= num; i++ ){
 echo "Number: i /n";
}

output =
Number: 1
Number: 2
Number: 3

Did you notice the 'num = count(array)', count() is a very valuable PHP function, which counts the number of elements within an array, so above we would get 3.


At the moment that's all I can think of pertaining to loops, if I forgot anything or you think I should add something then please comment or email or send out smoke signals lol.

Friday 29 June 2012

All about PHP arrays

Why write this ? Because I'm a web developer who never stores anything in his head, especially since google made searching the web even easier.

Anyway like I said, i'm a web developer at Computer Related (www.computerrelated.co.uk), in the UK. Well in Birmingham, West midlands to be precise.


I have many more tutorials and self help pages over at teachme.webege.com.

The basics

What is an array? I could get all technical up in here, but why! Really all you need to know is that an array stores multiple pieces of data in one variable.

OK maybe I need to be a bit more technical ;-) I find examples work best

Imagine the sum below

3 + 3 = 6
Easy. But long winded to change.

Now imagine this

x + y = z
$x = 3, $y = 3 and $z = both x plus y
Now we are working with variables. We can make x and y anything and z will always add up. Cool.

So what has this got to do with arrays? Everything. An array is made up of multiple variables. See.

For the next example I will create an array and add some data.

$array = array(4, 5, 8)
Now we have
$array[0] = 4, $array[1] = 5, $array[2] = 8

Do you understand what just happened? the variable $array was given 3 pieces of data 4, 5 and 8. The data is automatically stored in indexed order i.e 1, 2, 3, 4, etc.

So to access the data i just need to use $array[index], index being the actual index number.

Hold on, so why does it start from 0

Well spotted, we naturally count from 1 to 10 discounting 0, but computers count from 0 to 9. Hence 0 being the first index.

So what can I use an array for really

Well primarily instead of having for instances of 5 variables you could have one array, see below for example.

$one, $two, $three, $four, $five
or
$numbers[index]

We can also do cool stuff like use them in loops, but since I haven't discussed loops yet i'll leave that for now.

Back to arrays, lets say you want declare an empty array so you can add data later

$foo = array()
Now you can add to it like this
$foo[] = 23
That will add data to next free slot in array.

I don't want to use numbers for my index, i'd prefer to use words. OK, that can be done. It's called an associative array

$array = array("one" => 1, "two" => 2, "three" => 3, "four" => 4)
Now
$array['one'] = 1, and $array['two'] = 2, etc.

Suppose i have an associative array and I want it to be indexed instead? Of course we got a solution for that too.

$new_array = array_values($array)

Oh my days, I know that's what your thinking, yes it's that easy.

OK, how do i shuffle the array? If your not in PHP then long ting, but in PHP it's as quick as a quick thing lol.

$new_array = shuffle($array)

Done. I know, this PHP stuff is easy. Be carefull though, shuffle changes the index completely, wiping over old indexes.

Ok, you got this far so i'm going to give you 2 extra tips, not directly array related but near enough.

explode() is used to seperate a string at specific points (known as delimeters), i.e comma, fullstop, space, etc. Once exploded the data is then stored in an array.

$string = "hello, clarent, from, www.computerrelated.co.uk"
$array = explode(',', $string)

Now we have
$array[0] = hello, $array[1] = clarent, $array[3] = from, etc

Another cool tip is - Every string variable is an array. So

$string = "hello", then $string[0] = "h", $string[1] = "e", etc

If i've missed any usefull array stuff out please let me know so we can all grow.

Thursday 8 September 2011

Android. Why I chose it.

Intro

Hi all, my name is Clarent. I'm the director of Computer Related, an everything computer related service, specialising in software design and web development. I live in Birmingham, England and have a BSc Software Desing & Networking, and have been working within the industry for over 10 years. I'm passionate about technology especially anything Computer Related :-)
This article will hopefully give you an insight into the reasons I went Android, and hopefully help you make your decision, or just be a great read.

The beginning


Approximately 2 years ago, shortly after writing my first blog about the Nokia n97, I found myself jealous of the windows mobile, blackberry and iphone crew. They seemed to have it all. A stylish handset with excellent features and mass appeal. Now I know their may be many of you thinking "Hold on, the N97 is a good phone, and Nokia are one of the biggest mobile companies in the world". You'd be right, but in my experience they seem to be lagging behind the competitors, in terms of functionality and growth of the operating system (OS).

The search

The search was now on to find what I thought was the best mobile phone in the world. Yes the world, thankfully in this modern world we live in, the same power that is allowing you the opportunity to view this from where ever you are, is the same power that would allow me to buy from across the globe. Yes i'm talking about the great world wide web.
So first I used my internet best friend to help me find out what was causing a stir, his/her name was Google. At this time I knew google had an operating system used on the T-Mobile G1, but never imagined it would be the operating system for me. Previous reviews had not been that positive, so I seen it as a baby in the market that could not compete with the big boys.
I looked into the Iphone 4, I'd be pretty silly not too, as they advertise on t.v. about 50 times a day, and many people around me owned an Iphone and had nothing bad to say about it. But delving deeper into the Iphone scene made me realise that I don't want to be in Apples shackles, everything was so restricted, even creating and submitting apps was/is restricted. But why did everyone seem to love it then ? My conclusion was/is that Apple are marketing geniuses. To understand lets look back at a bit of history.

Phones started off basic, so basic that there was a stage when the phone too the left seemed like cutting edge technology. It had
  • no aerial
  • SMS
  • WAP
  • small in size / weight
  • cooler ringtones
  • games
I had one, and loved it at that time as much as I love my Android phone now (notice i'm not mentioning yet, what phone. Soon). The next big thing to happen to phones was colour screens and polyphonic ringtones, wow was that cool, of course it was, we was still in the days of single core computers and fat back televisions (Cathode-Ray).
Things where starting to move fast in the world of mobile communication, a whole load of then "smartphones" started to appear, the ability to use your mobile phone as a modem, windows mobile platform allowed us to use office products and surf the net on our phones, blackberries allowed us to receive push emails straight to our pockets/bags, things where getting good. Mini memory cards allowed us to save more and do more, we could now listen to mp3s another new technology.

The point

Now for all those reading this thinking "I remember them days", you where the first "smartphone" users, but many people never experienced this as it was seen quite techy. So to most a phone was just a phone to call on and receive messages. Most who already had a smartphone already used it to listen to music, take pictures, send and receive emails and surf the internet, but for those that didn't, a new technology came about. The Ipod. Music on the go, simple interface and stored a lot of music. Why mention the Ipod ? Well in my opinion this was a game changer. Those who had went out and brought an Ipod where also amongst the first o adopt the Iphone. Your music and phone in one, wow. Even though many had already been doing this. The fact that the Iphone had no multi-tasking or 3g or camera, made no difference to the Apple army. They had one thing no one else at the time had, the app store. Developers went crazy, users went crazy for what was developed and everything grew. The Iphone had become a dominant force in the mobile market. So why did I not get one ? Multi-asking, 3g, camera and all the restrictions posed by Apple. So I stayed Nokia, to be more precise I went N95 (Super phone), yes maybe there was no app store, but developers have always developed for Nokia, and it could install apps found anywhere. I had satellite navigation, Skype, Email, Music Player, Compass and many more apps.

The choice

Sorry people, I probably rambled on a bit up there. So back to the quest (it really felt like one). During my research one OS stood out above all the rest. Android. It was open source and had a lot of developers working on the OS, the app market seemed to be growing exponentially as with the fan base. but best of all, the operating system was offered on different phones from different manufacturers. The potential seemed endless.
Ok, I want an Android phone, but which one ? If I was American I probably would have been a Droid dude, but in the UK HTC was kicking up a storm leading the way. The Nexus one, Desire and Legend where all HTC phones and all seemed to shine in the dark. I quickly ruled out the Legend as it had the lowest processor power, the next to go was the Nexus one, the Desire had just beat it with a bit more RAM. The choice had been made, I had the money and now it was time to go Android, I still was not 100% sure I was making the best choice but went ahead anyway.

First Impressions

Wow. Was my first impressions. At this stage I knew nothing in-depth, I thought HTC Sense was standard on all Android phones, choosing the Desire was the right choice. HTC Sense worked like a dream. So smooth, fast and responsive. Within an hour I had the basic functionality down. Yes this was the best phone in the world to me. The new mission was on. Convert everyone to Android, and unlike our Apple brothers who all have to pay the same, we had an array of choice at an array of prices.
The fact that the Desire had a 1ghz processor, 512MB RAM, 512MB ROM, Amoled screen, not only 2g /3g but H (hsdpa) as well, memory card slot (extra 32gb) and Apps galore.
I only had to spend a minute and a half talking about the phone and everyone wanted it, those that could not upgrade their contract, or afford it chose within their limits, and this being Android meant that the choice was always growing. In 18 months I have converted about 90% of the people around to Android. That's about 25 people, and not one of them has complained. As a matter of fact many of those who had gone for a lesser option, have now upgraded.

Conclusion

Android rocks. Almost everything negative you here, is someone trying to burst the Android bubble, which is inflating even quicker that Iphone did. One of the main criticisms is fragmentation of the OS. Android 1.6, 2.1, 2.2, 2.3 and 3.0. Yes thats is a lot of different versions, but it is no different to Nokia and Windows Mobile. It gives the consumer more choice, shall I go for a cheap, mid range and top range phone, but still get the same basic functions and a uniformity. I can go on any Android phone by any manufacturer and not feel lost. I can stick with HTC or move to Samsung, LG or Motorola. That is the freedom of choice.
So what does he have now ? I here you asking :-)
That's easy. Only one of the most powerful phones ever created. The Samsung Galaxy S 2 (sgs2). Although I hated the Touchwiz (Samsungs user interface) on the sgs1, Samsung did their homework and now it rivals HTCs sense. The speed at which this thing flies is amazing, photo quality is superb and so is video, the internet is almost 100% the same as on a laptop or desktop PC, all flash videos work. Social networking is handled with ease, as with music playing, even though I had download a better music player app from the market. But there lies the power with Android, if you don't like something you can either find an app that would replace it, or as many of the manufacturers are allowing, tweak the whole OS. Can you really ask for more ? Not me.
So my final words are. If your not Android, check it out now. And if you are Android, well done and post your experiences below.

p.s. I haven't even gone into the custom rom and rooting path here today, but both my phones, and everyones around me is rooted and tweaked to bits, but that is for next time.