Paging with PHP

I trolled around the interwebz for a good 3 hours the other night looking for this.
I wanted to page through my mysql query’s resultset rather than display what could potentially be thousands of records on a single page. I wanted to limit the results per page to a certain, low number and display “Previous/Next Page” links at the end of that limited count.

Although I have to say that such a task is done very simply in asp.NET, I thoroughly enjoyed the challenge of doing it in PHP.

The first thing we need to do is find where the start of the page will be in the resultset. To do this, we pass a value to use in the mysql query. This value will just contain a number to indicate which page we’re on.

$page = $_GET[‘page’];
if (!isset($page)) {
header(‘Location: /mysite/index.php?page=1’);
}

$sql = ‘SELECT * FROM articles LIMIT ‘.($page – 1) * 10.’, 10′;
$result = $dbh->prepare($sql);
$result->execute();

foreach ($result->fetch() as $row) {
// Build each

here to display results.
}

$sql = ‘SELECT COUNT(*) FROM articles’
$result = $dbh->execute($sql);
$count = $result->fetch();

if ($page > 1) {
echo ‘Previous‘;
}
if ($count > $page) {
echo ‘Next‘;
}

The code might not be 100% accurate as I just wrote this off the top of my head. I hope it gives you an idea how to do this anyway.

Good luck!

– L

Studying again

I may have mentioned it before, but in case I haven’t, there’s a few Microsoft Certifications I want to get. Well, my target is an MCPD certification (that is, Microsoft Certified Professional Developer), but to do that one, I have to get an MCTS (Microsoft Certified Technology Specialist) first.

I’m happy to say that I’ve finally gotten my hands on a set of textbooks from which I can learn everything I need to get the MCTS; although, at this point, I can’t take the course for reasons I don’t want to bother mentioning.

The exams that make up the MCTS Windows Developer – that is, a specialist in Windows Forms development – are exam 70-536 (Application Development Foundation) and exam 70-526 (.NET Framework 2.0 Windows Based Client Development).
I know there’s more to the MCTS than this, but at this point, I’ll settle for what I can get. It’s still going to cost me my salary for 2 months to take the course, and that’s minimum expenditure.

At the moment, I’m working through the Application Development Foundation textbook and, although it’s taken me a week, I just started chapter 2 yesterday.
I had an idea about posting the lesson and chapter summaries over the next few weeks, but I’m not sure if that constitutes copyright infringement (if anyone can confirm, please let me know).

Thanks for your time and interest. Until next time…

-L

Life during unemployment

So, it came as a bit of a shock, but the folks at that eCommerce company I was working for when I started this blog decided to terminate my contract… They were very nice about it so kudos to them for that! I have no regrets about working there, and I hope that in the future, I might get the opportunity to work with them again (By the way – Zane, if you’re reading this, I’m still waiting for my reference letter.)

You’d think that life as a non-productive member of the public would be boring. You’d be right, although, the last two days (today included despite the fact it’s barely begun) have been quite eventful for me.
I was so happy last night because I’d finally managed to activate my copy of Windows Vista – no more notifications πŸ™‚
This was the highlight of my day because yesterday had really been slow and uneventful!

This morning was not so eventful in the way you’d want something to be eventful… No, it wasn’t something good that happened!
I was trying to get a few extra minutes of sleep this morning when the dog started barking right outside my bedroom window. To help you understand, my bed runs down the length of my room right along the window so, to have the dog barking just where he was barking is pretty painful for my ears. Normally to shut the dog up for a good half-hour, I knock on the window frame just between the two panes of glass.

What happened this morning is a result of this action… I missed the windows frame by roughly half an inch and knocked the +/-1m squared pane of glass out of the frame (old brittle window putty) and it broke into several hundred pieces on the ground…

Great way to start the day isn’t it πŸ˜›

I’d like to hear about your great starts to the day, post some comments people!!!

That’s it for this post really. On a side note, I’ll be continuing my visual basic guestbook soon. I just haven’t had the time what with replacing windows and looking for a job πŸ˜›

-L

The kind of weekend you DON’T want to have…

Last week friday, I was really looking forward to the weekend. It’s a long week, I have to get up absurdly early every day so a little R & R was going to be great, and so it was while it lasted.

Saturday night, I was “inspecting” one of my older brother’s newest possessions in his room. There were some friends there and some friends of friends and several people brought their laptop pc’s for multiplayer games later on in the evening.
The one guy (the guy who most of this post is about) brought his work laptop because he didn’t have anything else which would’ve been ok if he’d accepted the fact that in a social environment like that, especially with alcohol involved as it was, stuff is going to happen that nobody wants…

As I finished inspecting the new object my older brother had acquired, I placed it back on the shelf where I’d picked it up from. Apparently I didn’t do a very good job of this because it fell off the shelf and hit the friend-of-a-friend’s work laptop (the one mentioned earlier) and broke the screen on it’s way to the floor.
I didn’t notice at first because the screen was off so there was no way to see that it had been damaged. Upon realising I’d accidentally damaged the guy’s computer, I did the right thing and apologised to him about it and offered to give him the money for it at the end of the month when I get paid.

Understandably angry (and most likely drunk – I couldn’t really tell seeing as I don’t really know the guy), his response to my more than generous offer was a prompt “Dude, you better just get out of my face.”. That’s a direct quote.
Now I’m the hell in. He’s pissed with me about something I didn’t do on purpose, and now he’s threatening me – in my own house!!!
Thereafter, I rescinded my offer to pay for the damages as – from my point of view – he’s now rejected it and cleared me of any responsibility in the matter.

Yesterday afternoon, I get a call from my bud whose sitting with this guy – because they’ve known each other for a long time – and he’s asking me what I’m going to do about this whole situation. I told him that I’m not going to take liability for anything that happened because the guy who owned the laptop accepted the risk of it getting damaged when he brought it to my house. Eventually these people end up having the guy’s fiance to talk to me who then tells me (I’m paraphrasing here because I can’t really remember the whole thing) “We’re trying to sort this out civilly, but because you’re not willing to do that by taking responseibility for it, we’re going to lay a charge of malicious damage against you and we’re going to talk to our lawyer and sue you for the money. This means that you’ll have the police by your house a little later and you’ll be receiving a letter from our lawyers tomorrow.”

Well, I wasn’t arrested yesterday, and I’m not expecting a letter today or anytime this week in fact. I have to say that the thing that irritates me the most about all this is that there are actually some people who can’t accept that “shit happens” (think Forest Gump!!!).
I also have to say that since their “scare tactics” didn’t work, I’m very curious to see what they’re going to do now. My guess is that this whole story will just disappear…

-L

Don’t get upset with the guy behind the counter!

For the second time in my working life, I find myself in an industry I can’t stand working in. The first was working as a cashier at a local Pick ‘n Pay when I was 16, and now, a mere 5 years later, I’m working for an eCommerce company here in South Africa.

If you think it’s not the same thing, then consider the following:

  • Both are stores of some sort, and therefore, they sell stuff,
  • In both situations, I have to deal with customers, and finally
  • IN both situations, I fight fiercely with my body’s increasing need for sleep.

The only reason I took this job was because it pays well. It’s most data capture which falls into the Administrative Industry (my second least favorite industry to work in – the first being Retail).

The biggest problem with working in such an industry is that, on occasion, I have to tell my customers something they aren’t going to want to hear. This means that they are going to get upset and/or angry. When either of these two emotions comes into the picture, 90% of the time, the person in my position – be it behind a counter, or on the phone) get’s yelled at and basically treated like rubbish.

This is because the customer only sees the fact that (s)he hasn’t gotten what (s)he wanted. They don’t consider the fact that the person they’re yelling at has no control over the situation. It’s one of those “Kill the messenger” scenarios…

Lets face it, if my supplier runs out of stock or an order has been dispatched late, there’s nothing I can do about it! So next time you’re in one of these situations where the level of service you’ve received hasn’t met up with the level of service you expected, shrug you should, look disappointed, utter an “Oh, damn” now and then and be patient. You’ll get what you want – that’s what the retail industry is all about.
Don’t go off on a loud, angry tirade with the cashier/waiter/receptionist, it doesn’t help…

So that’s it from me for today. I’d like to thank you for your time and I’d also like to thank you for reading my blog. Comments are welcome, so don’t be shy ;-P

-L

Time to introduce myself

I’m starting this blog to tell you guys a bit about myself. I’ll also be sharing experiences I’ve had in my efforts to get an MCTS (Microsoft Certified Technical Specialist) and MCPD (Microsoft Certified Professional Developer) certifications.
For those interested,Β I’ll also be sharing stories about what happens around work (on occasion, I’ll be doing some promotions on specials we might have on at the time).

Obviously the fact that I’m saving up for Microsoft certifications means that I develop in .NET… I specialise in web development with the .NET Framework, but I’m also loving the Windows Form development side of things too.

Time for some vital statistics:

  • Full Name: Logan Charles Young
  • Age: 21
  • DOB (dd.mm.yyyy): 20.08.1987
  • Location: Alberton, South Africa

Watch this space, this is going to get big!!!