Everything PHP: MySQL Resources

Published on Aug 21, 2009   //  Development

Everything PHP

When you execute a query on a MySQL database through PHP, a resource is returned back to you. This resource contains the information that you queried from the database. However, a resource is not a data type we are used to working with, nor can we work with it directly like an array.

So, we’ll need to use other functions as sort of a bridge between a resource and something we can readily work with (an array). Today, we’ll be looking at a function that will allow you to get the data you retrieved from the database into an associative array. This is the function I use most often when processing database querys.

The function in question in mysql_fetch_assoc(). This function will convert the resource into an associative array, where the field name is the key, and the value of the field is the value of the array. Let’s take a look at an example of how this function works:

[php]$query = mysql_query("SELECT [field_names] FROM [table_name]");
$query_array = mysql_fetch_assoc($query);
print_r($query_array);[/php]

However, this function may not work as you would expect. This function will create an associative array from one of the rows from the given resource, it will then move the (internal) row data pointer forward to the next. So, to get the associate arrays of all the returned rows, we need to use this function in a loop.

As this function will return false once all the rows have been exhausted, the best loop to use would be while. Which you would use in a similar fashion to this:

[php]$query = mysql_query("SELECT [field_names] FROM [table_name]");
while ($query_array = mysql_fetch_assoc($query)) {
print_r($query_array);
}[/php]

You can now iterate through your MySQL resource and process the data how you need to.

Marketing 101: Pros and Cons of Early Promotion

Published on Aug 20, 2009   //  Marketing Tips

Does it pay to jump the gun and advertise something that is not yet available? This question not only applies to upcoming products that may not be launching for a few more months as well as upcoming sales that may be several days away. There are certainly both pros and cons to promotion something ahead on time.

On the one hand, early promotion can bring about a great deal of hype. You can get people talking about your product, service, or sale well ahead of schedule. This can help to generate some great word of mouth, informing and exciting people who may not have otherwise heard about what you have to offer. For upcoming product launches, it also means that you can gauge the relative interest of the public through their interest in pre-orders and similar promotions.

On the other hand, early promotion can frustrate customers because they may find that they are being teased with something that is not yet available. You may have heard about “vaporware” and these are products that are seen only as concepts and not yet in real life. As the release date gets pushed further and further into the future, potential customers start to lose interest in something that is too ethereal and not real enough. While waiting for your product, they may turn to a competitor for what is available right now.

Early promotion of an upcoming sale can also backfire. If people know that a certain item is going on sale in a week, they may not be willing to come into your store to make a purchase today. They’d rather wait. Early promotion of sales also give your competitors the opportunity to match or beat your deal, potentially grabbing away customers who may have otherwise purchased the product from your company instead.

What do you think? If you run a company, do you promote everything well before it is available or do you prefer to surprise your customers with announcements on the day that the product, service, or sale is available?

WordPress Wednesday: Stealth Login

Published on Aug 19, 2009   //  WordPress

One of the most important things you can do to ensure the security of your WordPress blog is to stay up to date with the latest versions of the popular blogging platform. These updates provide a series of patches to address security flaws and other bugs. However, there are countless other things you can do to thwart hackers and other people who may be trying to get into your WordPress dashboard.

Most WordPress users know that you can access the administration area of a WordPress blog by adding “/wp-admin/” or “wp-login.php” to the end of a blog’s domain. This can make it easier for hackers to guess your password and gain entry to the dashboard. To overcome this concern, Stealth Login can hide that login path, allowing you to define a custom URL where you can log into your WordPress dashboard.

For example, you could log in through “http://www.example.com/mycustomlogin” rather than through “http://www.example.com/wp-login.php.” If someone were to go to the latter and you have the Stealth Login WordPress plugin installed and activated, they would not be given the opportunity to enter a username or password. This plugin can also create custom slugs for logging out and registering.

To get more information on Stealth Login and to download the free WordPress plugin, head over to the WordpPress.org plugin repository.

Business 101: Underestimate or Overestimate?

Published on Aug 18, 2009   //  Business Topics

If you happened to be following me on Twitter over the weekend, you may have heard about my experience at Olive Garden: I waited far too long for my table. This wouldn’t have normally been an issue — if they’re busy, they’re busy — but my customer service experience was soured due to the way that the hostess decided to handle the situation. Allow me to explain.

I showed up at the restaurant to find a rather long list of people waiting for tables. I kindly asked the hostess how long the wait would be and she told me that it would be in the 50 to 55 minute range. I put down my name and I told her that I would come back in about 50 minutes and she said that would be perfect. During that time, I went to a nearby grocery store to get some shopping done and, right on schedule, I returned back to the Olive Garden 50 minutes later.

We approached the hostess again and asked if my name had already been called. She said that she called out my name 20 to 30 minutes ago and I missed my chance. The assumption, at this point, was that I would be placed back at the top of the list and I’d be next in line for a table. Instead, she said that because we missed our chance, we’re getting bumped all the way back to the bottom of the list. Even so, she said the wait from then should only be 10 to 15 minutes. I was slightly peeved, but 10 minutes was bearable.

Unfortunately, we were not seated for another 30 to 35 minutes! All in all, the total waiting time for my table ended up being an hour and a half. The hostess was not at all accommodating or compassionate. When we first arrived, she vastly overestimated the amount of waiting time, so I returned “too late” from buying groceries. Returning to the restaurant, she then vastly underestimated the amount of waiting time, so I sat in the lobby for far longer than I had expected. And I was getting very hungry.

This is completely unacceptable for a restaurant. If the initial waiting time had been quoted as 20 to 30 minutes, I would not have gone to the grocery store. She even told us that it would be fine if we left and came back in 50 minutes. Thankfully, the dinner itself was reasonably pleasant and the food was good.

If you were the hostess, how would you have handled this situation? Is it better to underestimate or overestimate the waiting time?

Web Development: Suggestions

Published on Aug 18, 2009   //  Development

Web Development

Over the last eight months of this Web Development series, we have covered quite a bit of material. XHTML, CSS and Javascript, which form the basics of the web. I am now opening the virtual floor up to suggestions for what we should cover next.

Do you want to see more in-depth examples of what we covered? Learn a little about XML? Something else? Leave your suggestions in the comments below, and we’ll see about writing about the topics that you want to learn about.

Great Gadgets: Verbatim InSight Portable Hard Drive

Published on Aug 17, 2009   //  Gadgets

Verbatim InSight portable HD

So, you’ve yourself a new portable hard drive with the intention of backing up your valuable data and carrying digital documents between computers and locations. For the average consumer, this may seem like a relatively simple process with any number of portable hard drives available on the market. You may find some that come with free backup software or a fancier-looking case, but they all function in fundamentally the same way, right?

Well, there’s one frustration that is shared with most of these portable hard drives. Looking just at the drives themselves, you oftentimes can’t tell what has been saved on it and how much capacity is left remaining for additional documents and files. This simple frustration has been simply overcome by the team at Verbatim with the announcement of the Verbatim InSight Portable Hard Drive.

By and large, this is still your regular run-of-the-mill portable hard drive, but it comes with one very notable difference. You’ll notice that there is a small display on there. This shows you the name of the disk volume and the amount of disk space remaining. The kicker is that this display will stay on even when the drive is not connected to a computer, since it has a small internal battery that supplies enough power for this simple functionality. I’ve seen similar displays in some USB drives, so this was a natural inclusion for a hard drive too.

The Verbatim InSight uses a 2.5-inch drive spinning at 5400rpm. You get 8MB of cache memory, USB 2.0 connectivity (bus powered), and a data transfer rate of up to 480MB/sec. The 320GB version is listed at $120, whereas the 500GB goes for $150.

Page 3 of 712345...Last »