ITT #12: Display Random Entries with PHP
I ran into an interesting problem while developing a new blogging system
recently where I needed to generate a subset of array elements in
random order.
A random subset of elements is useful for displaying a sampling of entries
that changes with every page load, such as four random blog entries, a
photo gallery that stays interesting even if new photos aren't uploaded,
or, if you want to use a sweet
content slider, you could show random portfolio or blog entry previews
and keep your slider fresh.
Defining the Problem
The Array
First things first, we need to know what we're dealing with. For the
purpose of this example, we'll be using a multi-dimensional
array that looks something like this:
$entries = array(
array(
'title' => 'Entry One',
'author' => 'Jason Lengstorf',
'date' => 'April...
read more
ITT #11: A Tip for Using Arrays
This week's Instant Tip Tuesday is a short one because I'm under some
pretty tight deadlines. I'm still looking for developers to help out by
guest blogging on Ennui Design, so contact me if you'd like to show
your developing chops!
On a quick vanity note, Chad
Engle did an interview with me
over on the DCTH site, so head over there and check that out!
Manipulate Arrays to Handle the First Element
Differently
Arrays, though they're incredibly useful, can also easily become
confusing. This is especially true when dealing with multi-dimensional
arrays, like a collection of entries from a database (a blog, for
instance, would have at least two dimensions in an array of entries: each
blog is an array of the different pieces of the blog, such as title,
author...
read more
ITT #10: Understanding OOP
NOTE: This comment by Cal Evans pointed out
an oversight on my part regarding naming conventions for classes. To avoid
conflicting with other classes, names should be distinctive, and as such, I
changed the name of the example class from "date" to
"Ennui_Date".
Recently, I've fielded a handful of questions concerning object-oriented
PHP. What is it? How does it work? Why should we care?
I had similar questions when I first started looking at OOP. I mean, why
the hell would I want to switch from the easy-to-understand procedural
method?
Classes and
objects might look confusing and difficult to manage at first, but they
actually significantly improve the organization and readability of your
code if used properly.
A Practical Example
Let's say, for instance, that we need to be...
read more
ITT #9: Build a jQuery Content Slider
I'm under some pretty tight deadlines, so I decided to kill two birds with
one stone this week: first, I told Brenelz I'd write a guest post for his
blog almost a month ago, and second, I've been meaning to write up a
content slider tutorial as an Instant Tip Tuesday post.
So in order to keep myself sane and on top of my ever-growing mountain of
work, I'm remotely posting this week's ITT post on Brenelz's blog.
Learn
How to Build a jQuery Content Slider
Share Your Instant Tips!
For the next month or two, I've got some really big projects I'm working
on, so I'm still interested in working with any of you and having you write
an ITT post for me. If you've got some ideas, or even if you don't...
read more