Archive for October, 2005

Average for the month: 63 cents a day. Average for the past 7 days, $1.24 – so over a 50% increase for the past week (and the day's not over yet!). Friday was almost $2 for the AIS site, Saturday made over $2.20. Yesterday was quieter at just 20 cents, but I don't expect much on a Sunday. Today I'm on 63 cents already and expect to wake up tomorrow to see a higher figure than that :) nnI've set up the new AIS site (still under wraps) with PHP includes so that we can get the design and CSS layout set up quite quickly and get the site up and running. There are over 600 pages to it so I'm going to use a random link list script within the link directory to ensure only 50 or so are displayed at any one time, but use a sitemap to ensure full coverage for spiders. Unfortunately I'm back in work for the next 3 days and out fixing a friend's computer tomorrow night, so I can't see me getting this site up until Thursday now :( I guess client work should also come first! I've planned out on the paper the ecommerce section so I may just write the code for that on the train back to Dave's on Thursday.nnSo far I have $47 in my adsense account (over a 2 year period!). I hope to have that doubled by the end of November. Watch this space!

So I've now left my car at Dave's as we need it more there and I can survive without it in Cardiff. However this means travelling by train twice a week – which isn't a problem and means I can relax more than when driving, however it does mean I have to take my little suitcase back and forth with my laptop in. My laptop is a heavyweight Dell Latitude C840 and I love it. Just over 3 years old and I've only needed a replacement harddrive when the other corrupted. Have since upgraded to a larger capacity and faster HDD but otherwise it's all the original build. But the downside is that it is quite heavy and large, as it's a 15" screen. Plus on the trains you don't get much room anyhow, and I travel for at least 1.5 hours from Crewe to Cardiff so I could utilise the time by doing some work. Whilst I can sit and plan stuff with a pen and pad, I'd rather be able to sit and type work up too.

I know there are 12" laptops out there, but all quite costly right now. However I'd rather have a 10" if they do them (anyone know?). This way I could sit on the train, do work, and not build up wrestler type muscles by lugging around a tonne weight bag! Unfortunately, well not so unfortunate, I am buying a digital camera at the end of the month which will cost not quite £200 so that's my big expenditure until after Christmas. By then I probably won't really have much use for a small laptop! Of course a windfall of money may come in any second now and I can get both!!

All variables start with the dollar sign $. Variables will automatically become the type required so there's no need to predefine them. For example: <?php $variable = "Hello"; ?> or <?php $variable = 5; ?> All strings have either double or single quotes around them. Personally I always use double quotes but this is a personal preference.

To print a variable you can use print but you do not require double quotes around the variable (however it will work with either method). The following are allowed: <?php
// set the variable
$variable = "Sarah";
//print a string with the variable in
print "Hello $variable, how are you";
// print a string with the variable 'concatenated'
print "Hello ".$variable.", how are you";
?>

Here both statements will display the same. In the second concatenation has also been used (the full stop / period "." ) – explained later.

Variables can of course have all arithmetic operations performed on them when in a number format, or string operations performed, when in string format. For example: <?php
$a = 2;
$b = 6;
// multiple a by b and store the result in c
$c = $a * $b;
print $c; // answer is of course 12
?>

Also another helpful option (will be important later on) is a variable of a variable. For example: <?php
$a = "name";
$$a = 3;
print $a; // gives the number 2
print $name; // gives the number 3
?>

This makes a variable of a variable. So at first $a is assigned to the string "name", and the the variable of the variable a, which is currently name, is assigned to 3. This will come in handy later on.

Commenting and documenting code is so important to make life easier later on when you return to your code and wonder why you did something specific.

All comments are started with two forward slashes // which will work on one line only.
Multiple line comments are better with /* at the start and */ at the end.
Also # will comment out anything after it as well, on one line only.

So back to our Hello World page from the previous thread. <html>
<head>
<title>Hello World Practice</title>
</head>
<body>
<?php
// line to print Hello World - a comment
print "Hello World";
/* this is another comment and it doesn't matter
what goes where so long as I finish the comment
at the end of this
print "Hello Again"; - this won't display
it's part of the comment
*/
?>

</body>
</html>

All php code starts with the following code <?php and always ends with ?>

While you can use shorter versions, for example: <? ... ?> it's more consistent and safer to use the full php tags.

As you'll have noticed with our first page using phpinfo(), the line of code is terminated with a semi colon. These are used to terminate every line of code besides control structures (more on these later). PHP and HTML code can be mixed in one page, however they cannot cross each other, ie. all php must be enclosed with the php tags, and if HTML is to be used within PHP then it must be presented in a particular way (see later).

So a simple page to print the typical 'Hello World' statement <html>
<head>
<title>Hello World Practice</title>
</head>
<body>
<?php print "Hello World"; ?>
</body>
</html>
Another word which does the same as "print" is "echo", however this tends to cause some syntax problems at times and seeing as there is no difference I always use print.

When using print, all strings are enclosed with double quotes. Single quotes can be used but a more consistent approach is double quotes. If you want to display a double quote within a print statement then you just escape it with a backslash eg. <?php print "He said \"Where are you going?\", and then walked away"; ?>

When this is interpreted, the backslash tells the interpreter to treat the double quote as a string and not a double quote. The following would not work: <?php print "He said "Where are you going?", and then walked away"; ?>

This would give a syntax error. However single quotes within double quotes are allowed in this situation so: <?php print "He said 'Where are you going?', and then walked away"; ?> would work fine.

Page 1 of 41234»

Latest Tweets