An Excerpt From Learning PHP, MySQL & JavaScript (Edition 4)

The 4th Edition of my book, Learning PHP, MySQL & JavaScript is now out, featuring tutorials on CSS, HTML5 and (in this new edition) the mysqli extension and a fully comprehensive introduction to jQuery, of which the following is just the first few pages, and which I have included here as a taster.

Excerpt from Chapter 21

The most striking thing about jQuery to people who are new to it is the $ symbol, which acts as the jQuery factory method. It was chosen because the symbol is legal in JavaScript, is short, and is different from customary variable, object or function/method names.

It takes the place of making a call to the jQuery function (which you can also do if you wish). The idea is to keep your code short and sweet, and to save on unnecessary extra typing each time you access jQuery. It also immediately shows other developers new to your code that jQuery (or a similar library) is in use.

A Simple Example

At its simplest, you access jQuery by typing a $ symbol, followed by a selector in parentheses, and then a period and a method to apply to the selected element(s).

For example, to change the font family of all paragraphs to monospace you could use this statement:

$('p').css('font-family', 'monospace')

Or to add a border to a <code> element you could use this:

$('code').css('border', '1px solid #aaa')

Let’s look at that as part of a complete example:

<!DOCTYPE html>
    <title>First jQuery Example</title>
    <script src='jquery-1.11.1.min.js'></script>
    The jQuery library uses either the <code>$()</code>
      or <code>jQuery()</code> function names.
      $('code').css('border', '1px solid #aaa')

When you load this example into a browser the result will be similar to the following figure. Of course, this particular instruction simply replicates what you can do with normal CSS, but the idea is to illustrate jQuery syntax, so I’m keeping things simple, for now.

Another way of issuing this command is by calling the jQuery function (which works in the same way as $), like this:

jQuery('code').css('border', '1px solid #aaa')

Modifying elements with jQuery

Avoiding Library Conflict

If you use other libraries alongside jQuery, you may find that they define their own $ function. To resolve this issue you can call the noConflict method on the symbol, which releases control so that the other library can take over, like this:


Once you do this, to access jQuery thereafter you must call the jQuery function. Or, you can replace use of the $ symbol with an object name of your choice, like this:

jq = $.noConflict()

Now you can use the keyword jq, wherever you had previously used $.

To distinguish and keep track of jQuery objects separately from standard element objects, some developers prefix a $ to the front of any object created with jQuery (so that they end up looking like PHP variables!).


Now that you’ve seen how easy it is to include jQuery in a web page and access its features, let’s move onto looking at its selectors, which (I’m sure you’ll be pleased to learn) work in exactly the same way as CSS. In fact, it’s at the heart of how most of jQuery operates.

All you have to do is think about how you would style one or more elements using CSS, and then you can use the same selector(s) to apply jQuery operations on these selected elements. This means you can make use of element selectors, ID selectors, class selectors, and any combinations.

The css Method

To explain jQuery’s use of selectors, let’s first look at one of the more fundamental jQuery methods, css, with which you can dynamically alter any CSS property. It takes two arguments: the property name to be accessed, and a value to be applied, like this:

css('font-family', 'Arial')

As you will see in the following sections, you cannot use this method in its own, because you must append it to a jQuery selector, which will select one or more elements whose properties should be changed by the method. Like the following, which sets the content of all <p> elements to display with full justification:

$('p').css('text-align', 'justify')

You can also use the css method to return (rather than set) a computed value by supplying only a property name (and no second argument). In which case the value of the first element that matches the selector is returned. For example, the following will return the text color of the element with the ID of elem, as an rgb method:

color = $('#elem').css('color')

Remember that the value returned is the computed value. In other words, jQuery will compute  and return the value as used by the browser at the moment the method is called, not the original value that may have been assigned to the property via a style sheet or in any other way.

So, if the text color is blue (for example), the value assigned to the variable color in the preceding statement will be rgb(0, 0, 255), even if the color was originally set using the color name blue, or the hex strings #00f or #0000ff. This computed value, though, will always be in a form that can be assigned back to the element (or any other element) via the second argument of the css method.

Warning: Be wary with any computed dimensions returned by this method because, depending on the current box-sizing setting, they may or may not necessarily be what you expect. When you need to get or set widths and heights without consideration for box-sizing, you should use the width and height methods (and their siblings).

The Element Selector

To select an element to be manipulated by jQuery, just list its name within the parentheses following the $ symbol (or jQuery function name). For example, if you wish to change the background color of all <blockquote> elements, you could use a statement such as the following:

$('blockquote').css('background', 'lime')

The ID Selector

You can also refer to elements by their IDs if you place a # character in front of the ID name. So, to add a border to the element with the ID of advert (for example), you could use this:

$('#advert').css('border', '3px dashed red')

The Class Selector

And you can manipulate groups of elements according to the class they use. For example, to underline all elements that use the class new you could use this:

$('.new').css('text-decoration', 'underline')

…If you want more please read the book, thanks!

Posted in Articles, Features | Leave a comment

They Made The 70s: 10cc

They Made The 70s: 10ccThe 1970s, was one of the most exciting periods in the history of popular music. Not only did it see the invention of disco and the roots of rap; hip hop, funk, glam & punk rock; smooth jazz, soul, and heavy rock & metal all prospered – aided by the arrival of synthesizers.

A video retrospective of 10cc – because, why not?

For many of the best known bands today, the ‘70s was their heyday, and this applies in no small amount to the group whose albums you would always find in the very first section at the record store: 10cc.

Signed in 1972 to his UK Records label by record producer Jonathan King, the band got its name from a dream he had in which a band of his, by the name of 10cc, hit the top of the charts on both sides of the Atlantic. Other rumours about how the band may have really been named are vehemently denied by its members.

The line-up of 10cc comprised Graham Gouldman, a prolific composer of 1960s hits such as Bus Stop for The Hollies, For your Love, for The Yardbirds, and No Milk Today for Herman’s Hermits; Eric Stewart, formerly of Wayne Fontana and The Mindbenders, whose most notable record was probably Groovy Kind of Love, a number 2 hit on both sides of the Atlantic in 1965; and the pair who later went on to form a duo, Kevin Godley and Lol Creme, who joined 10cc (along with Eric Stewart) from the band Hotlegs, hot on the tail of the novelty UK number 2 success Neanderthal Man.

Almost straight after deciding to create a new band, the newly formed 10cc recorded a little-known Stewart & Gouldman song, Waterfall (which later appeared as the B side for Rubber Bullets), and pitched it to Apple Records.

After hearing nothing from Apple for several months 10cc took the proposed B side of the Waterfall single and played it to Jonathan King at UK Records, who immediately signed the band after he apparently “fell about laughing”, declaring: “It’s fabulous, it’s a hit.”

Taken from the self-named album, 10cc, that song was called Donna, and it became the band’s first UK hit, peaking at number 2 in 1972, with the help of Radio 1 DJ Tony Blackburn making it his Record of the Week.

After the almost instant success of Donna it might have seemed that 10cc were on a fast track to the top, but that wasn’t the case because when the band repeated the 50s doo-wop and falsetto style in their next record, Johnny Don’t Do It, it didn’t even make it into the charts

So 10cc released a single titled Today, under the band name Festival, which also failed to chart.

Undeterred by these failures, 10cc bounced back with their next single, Rubber Bullets, a five minute tour de force that reawakened the record-buying public’s interest by climbing all the way to number 1 in both the UK and Ireland, but only just entering the US top 100 at number 73. Incidentally, Sergeant Baker was probably the father of one of Kevin Godley’s early friends.

This song attracted a fair bit of controversy at the time because of the British Army’s use of rubber bullets to quell rioting in Northern Ireland. And success still didn’t come easy for the band after this either, as it released several singles during the course of 1973 and 74, including the UK number 10 song The Dean and I, followed by Headline Hustler, a cover of Da Doo Ron Ron (released under the band name Grumble), and the tongue firmly in cheek single, The Worst Band in The World, from the album, Sheet Music.

And indeed, by the end of 1974 three out of four of 10cc’s recent singles had failed to chart (The Dean and I being the exception), but the band never gave up hope of another top 20 hit, which finally came to them in the form of the UK number 10 single, The Wall Street Shuffle, which deals with Wall Street (which the band were driving down when they came up with the song), the economy, and specifically mentions Getty, Rothschild and Howard Hughes.

In typical fashion for the band, Silly Love, the track 10cc released after The Wall Street Shuffle, was the last single from the Sheet Music album, and it only just scraped into the UK’s top 25, and virtually nowhere else in the world.

So it was down to the subsequent song to save the day again, which this time was 1975’s Life Is a Minestrone (the title having been picked up from a talk radio show), and which reached number 7 in the UK.

While Life Is a Minestrone, from the album The Original Soundtrack, did chart in the US, its highest position was number 104, only one less than 10cc had achieved with The Wall Street Shuffle. No matter how hard they tried, the band had steadfastly failed to achieve major success in the USA. Could they do so, though, with their next single from the album, I’m Not In Love, also released in 1975?

Written by Eric Stewart around a Bossa nova beat, Lol Creme changed the song’s tempo, while Kevin Godley suggested replacing the beat with a layered wall of voices comprising numerous overdubs, and the rest, as they say, is history.

Not only did I’m Not in Love storm straight to number 1 in the UK, Canada and Ireland, it made it to number 2 in the USA.

And history indeed was made, because it finally launched 10cc to international superstardom, and brought the band a highly lucrative five album, five year deal with Phonogram, who upon hearing the track for the first time said “This is a masterpiece. How much money do you want? What sort of a contract do you want? We’ll do anything.” What a great position to be in.

So, fired up with the success of I’m Not In Love, 10cc followed up with a string of fairly successful singles, most of which charted quite highly, starting with Art For Art’s Sake, from the How Dare You! album, their last release of 1975, and which made number 5 in the UK, but sadly didn’t repeat the success of their previous number 2 American hit, languishing at the bottom of the top 100, at a highest position in the USA of number 83.

The title of Art For Art’s Sake was taken from a phrase Graham Gouldman’s father often used to say, in a similar way that many of 10cc’s song titles were thought up – from things the band saw or heard, such as the time Eric Stewart saw an advert for American Airlines in which a beautiful stewardess was inviting passengers onto a plane, and came up with 1976’s I’m Mandy Fly Me, also from How Dare You!

Sadly 1976 was the year that 10cc split up after their close personal and working relationships had begun to fray when frictions mounted between the group’s two creative teams of Stewart & Gouldman and Godley & Creme, during the recording of How Dare You!, with each pair realising how far apart their ideas had grown. With the recordings over Godley & Creme left the band to work on their own projects, which included the release of the 1980s hits Under Your Thumb and Wedding Bells, which reached numbers 3 and 7 in the UK respectively.

Stewart and Gouldman soldiered on, however, bringing in drummer Paul Burgess, and their first album as a three-piece band was 1977’s Deceptive Bends (named after a sign on the A24 between Leatherhead and Dorking).

The album featured three single releases, Good Morning Judge, which got to number 5 in the UK (and 69 in the USA), People in Love, which failed to chart in the UK, but reached number 40 in the USA, and The Things We Do For Love, which brought back much of the success of the earlier four-piece band, hitting number 1 in Canada, number 6 in the UK and number 5 in the USA.

The new 10cc was to have one last major hit in the 1970s (and, indeed, in any decade thereafter), and it came from their Bloody Tourists album of 1978, in the form of the reggae classic, and every cricket lover’s song, Dreadlock Holiday.

The remaining members of 10cc stuck together until 1983, recording a further three albums, but with very little reception in the UK, with singles only occasionally making the charts, and very little happening in the USA.

Then in the early 1990s the original band members reunited to record a new album (called Meanwhile) and to tour Europe and Japan. Then after another 15 or so years on individual projects 10cc began touring again in 2010, and were still touring in 2013, supporting Status Quo on a tour of medium to large arenas, although only Graham Gouldman remains from the original line-up.

With five gold, and two silver albums, eleven top 10 singles (including two number 1s and a pair of number 2 hits) all in the UK, and two top 10 hits in the USA, 10cc was one of the most popular and inspirational groups of the 1970s, and part of the soundtrack to the lives of everyone growing up in that decade.

Posted in Articles, Features, Media | Leave a comment

Is there another universe in the opposite direction of time?

Is there another universe living in the opposite direction of time?What if the big bang also exploded backwards in time, and 26 billion years in the past, there is/was a whole other universe living in the opposite direction?

The preceding has been my Twitter tag line for about a year, and so I was very interested to encounter the following article from the Telegraph this morning: Did the Big Bang create a parallel universe where time goes backwards? (and the Daily Mail) about a paper entitled Identification of a Gravitational Arrow of Time, in which an international team of scientists led by Dr Julian Barbour challenge assumptions about the so called ‘arrow of time’:

“The ‘arrow of time’ is the theory that time is symmetric and therefore time moves forward. They contend that there is no scientific reason that a mirror universe could not have been created where time moved in an distinct way from our own.”

According to the paper, The arrow of time is also known as the ‘one-way’ direction of time and was devised by a British scientist, Dr Arthur Eddington, in the twenties, and a mirror universe is a possibility because all of the laws of physics apply no matter which way time is moving and therefore there is no scientific impediment to such a parallel universe.

Actually I think this doesn’t go far enough

While I think it’s great that notable scientists are considering these things, I believe that Dr Barbour hasn’t gone anywhere near far enough. You see, we already know a lot about the first three dimensions (up/down, left/right, and in/out), but we seem to scratch our heads when it comes to time, and even wonder whether it’s a real or a pseudo dimension.

But here’s how it works. Just like the first three dimensions of space, in which you can move back and forth along each dimension, so you can in time. It really is the fourth dimension, and it’s at right-angles to all the others. Therefore, because of this, you can theoretically travel backwards and forwards in time.

But the thing that stops us is that (in the same way that the Universe is ever expanding from the Big Bang), all the observable matter in the universe has been thrust in our direction of time (which we refer to as forwards). A huge amount of energy has created an almost unstoppable inertia of matter travelling through time. Because this matter is all moving forwards through time at the same speed, we assume that there is an ‘arrow of time’.

There is no ‘arrow of time’

However, there is no ‘arrow of time’. It’s a concept that’s meaningless, because there is only the velocity of matter through the fourth dimension; the matter that surrounds us is simply travelling in the same direction through it as us, simply due to the massive Big Bang explosion that sent it flying.

Now, here’s where we catch up with Dr Barbour’s suppositions, because it seems very likely that with the huge amount of energy in the Big Bang, no way was it all directed in only one direction of time. It simply has to have exploded ‘backwards’ in time too, so that half the matter in the universe went the other way.

What also seems likely is that, because time effects are fully reversible, cause and effect can work backwards in time in exactly the same way that they do forwards, and for intelligent beings thrust 13 billion years backwards in time from the Big Bang, it will seem to them that they are going forwards in time, and you and I will be just theoretical possibilities to them.

Further food for thought

Once you switch from thinking of time as being unidirectional, to it being fully a fourth dimension (and therefore no-longer referred to as space/time), you can look at all four dimensions collectively from the point of view of the Big Bang forwards until the present, and also backwards from it by the same amount (or distance) of time.

But why stop at four dimensions? Now that time isn’t confounding our thinking and is truly a dimension, is there, then, a fifth dimension? And if so, what is it like? Firstly, to help get our heads around this concept, let’s totally dismiss the idea that other dimensions are curled up so small that we can’t see them. OK. This may actually be the case, but assume it isn’t.

So now we start stepping into the area of parallel universes. You see, if there’s a fifth dimension, then the Big Bang surely exploded into it as well, in both directions! So what does that mean? Well, it means that the multiverse would have to exist, and that it might be possible to somehow travel between these universes, if only we knew how to move sideways.

We travel through the multiverse all the time

So why can’t we move sideways in time and experience these universes? Well actually we do – all the time. Every decision we make, every time an electron chooses one slit over another to go through, every thought we have, and everything we do moves us between the parallel universes.

As you know, all dimensions have to be at right angles to each other, and we can just about perceive that time is at right angles to the first three dimensions, but what would be at right angles to all four of the first dimensions?

Clearly the line of the fifth dimension would have to travel in entirely different directions to be at 90 degrees, and what is a more different direction than the action of thought or choice itself being the fifth dimension?

Let’s take this even further

This leads us to ask what, therefore, would be the sixth dimension? (and by the way, how many dimensions are there – infinitely many?) So let’s go out on a limb here and try to find something else that’s at right angles to the first five dimensions. What might fit the bill? How about consciousness and emotions?

Could it be that things such as our senses (known as qualia), and our self-awareness can be explained only in terms of a highly multidimensional universe? Would this account for the effects of quantum mechanics? Given the growth of technological advances, rather than just theorising, will science soon come to acknowledge the existenceof  more than the four dimensions of space and time? I think it will.

And that’s about as far as I can take this right now, although I suppose that some people might just imagine getting up to a seventh dimension by considering spirituality. But beyond that, our small brains may not be powerful enough to imagine (although maybe AI will help there).


Oh, and if there is no ‘arrow of time’ then yes, of course we can travel backwards in time (relative to our current direction), it’s just that the energy required to do so would be immense (to counteract that imparted by the Big Bang), and we’d also have to avoid colliding with all the matter coming forwards at us as we travel backwards. As they might say on Mythbusters: “Plausible, but highly unlikely”.

Posted in Articles, Features, Observations | Leave a comment

Drink For Thought…

Soda Infographic

Posted in Features | Leave a comment

Philae, the Rosetta probe, has touched down on the comet

After spending ten years circling the Earth and Mars, then waiting in deep space for over two years for comet 67P/Churyumov-Gerasimenko to pass by, the European Space Agency’s Rosetta mission has now successfully landed its Philae probe on the comet. This heralds a new era of space exploration, and new (almost unlimited) potential sources of precious minerals. This short movie, called Ambition, was made for the ESA to accompany the landing – and it is spectacular.

Posted in Media, News | Leave a comment

Yin into Yang; and Yang into Yin…

I never realized how closely related the two halves of the yin-yang symbol are:

Posted in Observations | Leave a comment

Installing the Windows 10 Preview in a Virtual Machine

Do you want to try out Windows 10 for yourself, but are worried that it may be interfere with your current setup? Have no fear because this video shows how you can easily install the full preview in a VirtualBox virtual machine. That way it is fully sandboxed and your computer is protected from potential bugs. What’s more, none of your current settings will be modified, and you can even install the preview on a Mac or a Linux PC, too.

Posted in Features, Media | Leave a comment

My new book series will be out in January

I have a new series of books, 20 Lessons to Successful Web Development, coming out in January. So far there are four books in the series, covering PHP, JavaScript, HTML & HTML5 and CSS & CSS3. Each book contains 20 lessons, which you should be able to complete in under an hour each, including the accompanying free online video tutorial that comes with each lesson. In total each book has over four hours of video and dozens of tested and working, easy-to use examples.

You can pre-order your copies at all good bookstores and online retailers. Here’s a link to the books on Amazon. The examples can all be downloaded for free at

Posted in Media, News | Leave a comment

Store it as fat!

Science is funny at Beatrice the Biologist

Posted in Humor, Media | Leave a comment

Thanks Scotland

Whichever way you voted I want to thank all the Scottish people for benefiting the union as a whole. The consequence of your referendum is that the English, Welsh and Northern Irish will now also get a much bigger say in how they are governed at a local level, as the UK reinvents itself into a modern federal democracy, similar to the USA.

Now we have to address the other big question that’s quickly coming our way – what to do about Europe…

Posted in Observations | Leave a comment