Entries tagged "database"

Help Visitors Find Moved Pages with a Simple Error 404 Database

Does your Error 404 page let visitors know where a page has moved to? Or does it have a generic message saying the page has moved and requires the visitor to find the page on their own? With a relatively simple database table and a few lines of code, we can enhance the error page and help customers find what they want faster. [Continue reading]

Quickly Enter Today’s Date in phpMyAdmin

With the date-field types, phpMyAdmin provides a pop-up calendar for quickly selecting a time frame. However, I commonly create new entries by editing an old row and choosing the "Insert as new row" option. Using older entries causes the calendar to show dates based on the original entry. Since phpMyAdmin doesn't have an option for jumping to today's date, I end up clicking through the calendar options or typing the date manually. Well there's another, sometimes faster, way. [Continue reading]

Build HTML Tables Dynamically with PHP Part 3: CSS Alternative

Using HTML tables for design is typically frowned upon in the Web community and the last two posts talked about using tables to display pictures and names in rows of three. For those unfamiliar with the CSS alternative, I didn't want to leave you hanging. So let's look into solving our problem with CSS. [Continue reading]

Build HTML Tables Dynamically with PHP Part 2: Simplify with array_chunk()

Last week we built an HTML table on the fly using PHP. The process required a counter for monitoring which column was being displayed and some tests to determine when to add row tags. Let's look into simplifying the process with a built-in PHP function called array_chunk(). [Continue reading]

Build HTML Tables Dynamically with PHP Part 1

There is a built-in PHP function which would have really been useful back when using HTML tables for design was popular. Instead of setting up counters and testing when to add the opening and closing tags, we could have just read in the data and displayed it. Let's pretend we're back in the heyday of table hacking and look how the function saves time. [Continue reading]

End PHP Scripts Gracefully After a Failed Database Connection

Last week's post talked about externalizing the MySQL connection script for easier maintenance. The problem with the previous code is that it's not very user friendly. If the database connection fails, it just drops everything and displays an error. Well, there's probably other content on the web page that can be viewed without database access. The website navigation, for example, most likely doesn't require a database. The navigation will probably lead to other pages that don't need that database. To minimize the impact to the visitor, let's look at a more graceful solution for handling connection failures. [Continue reading]

Maintain Your Database Login Information with Ease by Externalizing the Connection Script

When working with databases like MySQL, a connection needs to be established before processing any queries. That connection script could be added to the top of every page needing access, but what happens when the database password needs updating. Who wants to update dozens (or thousands) of files? As a solution, let's look at externalizing the code that makes the connection and importing it instead. [Continue reading]

Before Deleting a Database Table, Change Its Name

When a MySQL table is no longer needed, it could be deleted. However, are you sure that the necessary changes have been made so that the website is no longer connected to the table? It's tough to know for sure when the old database table is still available for querying. If the table is removed and it's still being used, it takes time to fix the connection(s). The database table could be restored until everything is fixed, but that's going to take time also. Instead, let's consider renaming the table before permanently deleting it. [Continue reading]

Minimizing MySQL Queries with the implode() Function

After seeing the many warnings that MySQL queries shouldn't be executed within loops, I finally broke down and figured out an alternate solution for the majority of queries where I use loops. Most times, a loop feels necessary when one database table contains the core information and another has multiple entries of supporting information. Instead of going for the typically loop, let's look at using the implode() function. [Continue reading]

Building the Where Clause for MySQL Dynamically

There are a number of ways to dynamically build the WHERE clause for a MySQL query. You could, for example, run several if() statements in the middle of a query. Or one could tap into the power of the implode() function. [Continue reading]