Entries tagged "MySQL"

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]

Using phpMyAdmin as a Checklist for Columns Used in a Script

One of my many coding habits I've been changing is the use of select all (SELECT *) in MySQL queries. Scripts usually don't need all the columns and grabbing unnecessary data reduces efficiency. Fixing the references usually involves me digging through the code, remembering the column names actually being used, and updating the query. This method works well when there are only a few columns to worry about. It gets more complicated with more columns or when they're used throughout a large script. That's where phpMyAdmin comes to the rescue. [Continue reading]

Avoid MySQL Queries Within Loops

One consistent piece of advice that's given on PHP help forums is that queries shouldn't be executed within loops. However, they don't usually provide an alternate means for accomplishing the task at hand. So I wanted to share a solution which fixed one of my scenarios. [Continue reading]

Why Does the fetch_array() Function Even Exist?

When looping through a MySQL result set, which function do you use? My preference has always been for the fetch_array() function since it allows access to the data using the database column names. However, is that the most efficient function to use? [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]