Tip:
Highlight text to annotate it
X
But, you know, we can reduce this even more. So part of the problem here is that we have
our list of products in our product page and that's the full list, but then when we look
at our header, we duplicate this a bit. We add our mahogany and our bamboo products here
to our featured product listing. But the prices for mahogany here and bamboo here are going
to need to be identical to the products listing for mahogany and bamboo here. Also if we change
the product image or the title, then you need it changed in the featured listing bar as
well.
So what would be ideal is if we had a master list of products and we can pull out individual
products for different types of displays. For the product page we would want to display
all of the products, but for our featured sticks sidebar we would just want to add two
items there. In the future we could extend this to include more or we could create additional
types of listings, but it would all pull from the same master set of products.
So if you've already worked through the videos dealing with MySQL and databases, then you're
probably thinking that a database is the perfect place for this information, and you're right.
But we're going to take one more step before we get to the database to demonstrate the
power of unique identifiers.
So in one of our previous examples we were dealing with a database of users, and in order
to convey to our script which user we were working with, we used the username for the
user. But what this meant was that the username could never change. It assumed that we would
never want to change that. But what happens if the user accidentally misspells their username
and needs to modify it later? Well, in that case, it would make sense to have a different
kind of identifier that was completely different from the actual data in the record.
Now these unique identifiers can take one of two forms. Most commonly in Drupal this
takes the form of an autoincrementing number. So every time you have a new record, it gets
a new number that's one more than the latest record. So the first record for a particular
piece of data would have the unique identified of 1, the next one would have 2, the next
one 3 and so on.
And one important quality of that type of unique identifier is that numbers are never
reused. So for example, if we have ten records and we delete one, we don't create another
record with the idea of ten. We just move on to 11 even though there's no 10 anymore.
Another type of unique identifier is a hash or often called a universal unique identifier,
and this is a long string that contains all kinds of characters in it, and it's so random
that the chances of another one occurring that has the same identifier is so small that
it will pretty much never happen.
Now Drupal by default doesn't use this type of identifier very much. Normally it defaults
to the autoincrementing type. And we're going to go ahead and follow suit by assigning a
unique identifier which is a number to each one of these products.