Anyone who's wanting to learn PHP and MySQL should be considering SitePoint's Build Your Own Database Driven Website Using PHP & MySQL by Kevin Yank. I've just finished reading this book and have to admit, I wish I had this book to learn from when I first learnt PHP a few years back.

You may be wondering why I've been reading a book that's clearly for beginners. Couple of reasons. I learnt PHP when version 4 had just been released. The book I learnt from was out of date within weeks simply because of the major changes that happened, default settings etc. Whilst it was a great book to learn from there were parts that I'd either skipped (Object Oriented Programming for a start!) or just parts I'd never really grasped. Knowing how well SitePoint books are written, I decided to buy this book to give me a chance to refresh my knowledge, pick up on any changes for PHP 5 and also have an up-to-date PHP book on my shelf.

So what will this book teach you? It will teach you the basics of PHP and using MySQL. It explains how to use PHP to create dynamic webpages, how to store the content of a site in a database and retrieve that information and display it on the site. How to allow people to add to and update that content. It goes into regular expressions, the basics of PHP's file access methods, good structure using includes and more.

I recently had a chat about this book with someone who wanted to learn the basics a bit better but had looked at the free chapters of this book and got completely confused by its complexity. If anyone else has been or finds themselves in the same situation then I know where you're at. Ignore the first 2 chapters initially! The first chapter goes into how to set up PHP and MySQL on your computer. Whilst I used to do this myself now I recommend using Xampp. It's easy to install, comes with everything you need and can also be run off an external drive or USB pen drive, so you don't even need to put it on your computer! Then the second chapter of the book goes into MySQL. Again, not something you need to concern yourself with at first. So skip to chapter 3 and things shouldn't be as complex and scary!

So if you want to learn PHP then I highly recommend this book for the basics. You can get 4 free chapters from the SitePoint page or you can buy the book cheaper with free delivery from Amazon UK.

At times you may find that you want to have a few extra gimmicks (links, widgets etc) displayed to you on your WordPress site however you don't want visitors to see these. Perhaps it may be an admin link, to save you having to type it in, or maybe a widget of some kind. This is easily done with a little bit of code as shown below:

<?php
global $userdata;
if ($userdata->ID > 0) :
?>
Put your output here
<?php endif; ?>

The first line of this code makes the userdata variable global so that we can access information from it. Then we check the ID of the current user. I've set it so that it checks to see if the ID is greater than zero, ie. it's a logged in user. This would mean anyone who's logged in would see the content you output. Then, where it says 'Put your output here', is where (obviously) you put your output! This can be anything you want. I've used it in the past for quick admin links through to wp-admin, testing additional sidebar content so that it doesn't disrupt the actual site, plus I have a couple of widgets display on the left side of the screen which just gives me a bit more info but stuff I don't want to necessarily have public.

If you have other users and you don't want them to see what you can see, then you can change the if statement to check that the user ID is your admin ID. This is usually 1, however you may need to check on this. This is easily done by going to Authors and Users and looking at the ID number next to your name in the list of users. Once you have this ID then simply change the if statement to:

if ($userdata->ID == X) :

Where X is your ID. Note the two equals signs. Make this is 2 and not just 1 else everyone will see the hidden output and you could also cause other problems on your site.

Then finally you close the if statement when you've finished the output you want kept hidden from the public. This doesn't have to just be used for a one liner, it can be used to output anything you want from one line to many. You can even use an if/else statement so that you display one thing to yourself and something different to everyone else. Of course you don't want to go overboard with this else you would have to always to ensure you checked your site without being logged in, just to check that nothing's gone wrong ;)

If you want to repeat this within the header, content, sidebar or footer, then you only need the global $userdata line once before the first time you use the if statement.

PS. Yes I didn't know what to call this post which is why it's a bit naff!

I missed last week's post as I didn't really have a great deal to say! This week things have gone up and down like a rollercoaster! We'd been holding out for the opportunity of renting this house, well priced, well located etc. The owner's manager had told us last week to call on Monday to arrange a viewing. We'd been discussing this house with them for well over a month, trying to get a viewing for the past few weeks. So Monday came and Dave gave the guy a call and was simply told 'oh that house has gone now'. I'm sure you can imagine how unhappy it made me. We'd spent so much time waiting on these people to just be told that the house had gone after we had done everything we'd been told to do! I don't understand why people can be like that to others.

After this low I spent the afternoon on the estate agent sites again, as our other contact hadn't bothered to phone us either, and figured that we'd just have to deal with losing £200-300 in fees. I found a couple of houses and Tuesday morning called up about viewing them. We saw a house on Tuesday afternoon, a 3 bedroom place, with a driveway, in a quiet area about 20 minutes north from here. Whilst it's not 100% perfect, we worked out how we could sort the furniture out and that it would be okay for a while. So we put in an application for it (Non refundable £220 fee) and we're just waiting to hear back about whether we've been successful or not. I have to say, I've never had this much hassle trying to rent somewhere before! It was easier than this in London! Not to mention fee free.

Monday also saw the release of my second plugin which I'd needed for client sites. It's not provoked as much interest as my first, however the comments I have seen have been good, often including 'why isn't this functionality already in WordPress?' Which is a good question, but with WP being a blogging platform, pages are not meant to take priority so I can understand it :)

On Thursday my parents turned up (12 hours early!) after a few days in West Wales. They'd been planning to stay in Bangor on the Thursday evening but with the bad weather, no train to take them up mount Snowdon, and lack of much else to do, they arrived up here in the late afternoon. This was a nice surprise, especially as I'd been alone all day as Dave was in Yorkshire at a funeral. On the Friday we showed them the house we're hoping to move into and then popped over to the beach to grab the best fish and chips around for lunch. Afterwards they headed home and left us catching up with work for the afternoon.

This weekend has been a fairly lazy one. Dave's been ill with potentially fatal man flu (that'd be a cold to us girls ;) ) and besides going out for more Lemsips, I've just been catching up on a bit of work while trying to take it easy a little. I've got a day trip to Cardiff tomorrow for work, so I have about 7 hours on a train to put up with. Thrilling! ;)

In my latest plugin, Custom Title Attributes, I needed to learn about Pattern Syntax to get what I needed working. To put this simply, I needed to replace one specific section of a string with another. Usually this would be easily done using the string replace function, however this only works if you know what string to search for in the first place.

With my plugin I had to match a pattern instead of a specific string to get what I needed. This can be achieved using a form of preg_replace() which was the preg_replace_callback() function. I'm not about to go into detail as to how these work just now. My point of this post was simply to mention the page (besides the PHP manual) that has really helped me out and explained things so clearly that I felt it deserved a mention and a thanks. So if you're interested in understanding pattern matching and regular expressions then I highly recommend reading WebCheatSheet's article – Using Regular Expressions with PHP.

More clients are slowly getting the idea of accessible websites into their head. You'll often find clients asking for something they've seen on another site, it's only natural. One fancy little thing is the option of allowing people to click a button that controls the font size of the site. Yes, a good browser should do this for you (providing your style sheet is coded to allow it) however a lot of people do not realise that they can alter the size easily via the View menu. Your best option is to educate your visitors but not everyone is prepared to sit and read about how they can use their browser properly.

I see people asking about a font size switcher and are usually told to use JavaScript or are perhaps referred to an old article on A List Apart called PHP Switcher. Personally, I wouldn't use JavaScript as not everyone runs it. I know people who have played with their settings and switched it off without realising it, and others choose not to run it. Plus, why use JavaScript when a server side language can do the job just as well ;) The PHP Switcher is a good article however it's not exactly what people are looking for, as this creates a drop down list, a jump menu essentially, using older PHP code (no Super Globals in use there!). I may have missed a more recent PHP Switcher article on ALA, but on a quick search I couldn't see anything jump out.

So how is it done with minimal work? It's fairly straightforward. First off I have to point out that any switcher will need to rely on cookies unless you intend to pass a variable through to every page on your site which will create a lot more work. A cookie is also ideal as it means that if the visitor returns on another day it can continue to remember their settings and this way they don't have to increase the text size again.

Continue Reading