My Guy Solutions

Posts Tagged ‘How To’

Convert SQL Formatted DateTime Into More Readable Format Using PHP’s strtotime

July 20th, 2011

By using PHP to work with the very popular SQL column type DateTime, it is possible to format a timestamp in any configuration. PHP quickly and easily enables a simple, robust and handy function to represent DateTime in any format you see fit.

PHP’s time() uses Unix timestamps for its date functionality, but contains functions to convert any other timestamp into the exact date formatting (text or otherwise) you are looking to accomplish. This includes working with SQL’s popular DateTime format.

As mentioned PHP uses Unix Epoch time, or POSIX time, it is a system for describing points in time. It is the amount of seconds between January 1st 1970 00:00:00 (Unix Epoch) and the present time, to the closest second. It is widely used not only on Unix operating systems, but in many other computing systems including PHP and the Java programming language. PHP’s own time() uses Unix epoch time. This makes it necessary to convert DateTime into a format PHP is comfortable working with.

(more…)

Using PHP’s var_dump() to Display SQL Query Results

July 7th, 2011

Using the power of PHP’s var_dump() displays structured information about one or more expressions that includes its type and value. By definition var_dump() is a debugging tool, which displays structured information about any PHP variable. Below is a handy bit of code using var_dump() to test and verify that a SQL query contains data and view the contents using PHP:


$sql = mysql_query("SELECT * FROM your_table WHERE key = 'value'");
$assoc = mysql_fetch_assoc($sql);

// Dump variable containing the result of the MySQL query
var_dump($assoc);

(more…)

How To: Enable the Use of Sessions On Your WordPress Blog

April 14th, 2010

WordPress does not use sessions to hold any data being that it is a stateless application. This makes it quite a problem for tasks like a shopping cart, which requires data(the user’s selected product) to be remembered from one page to the next. This means that if you want to use PHP sessions in your plugins or custom modifications of WordPress you will need to do some custom coding.

Luckily the fix is a simple one that anyone can handle! You only need to do a little hacking to enable sessions within WordPress.

(more…)

How To: Fix WordPress 404 Errors on Password Protected Directories

February 10th, 2010

Using WordPress’s permalink feature seems to cause some issues with password protected directories that use Apache’s .htaccess to handle authentication. I recently had to troubleshoot why after installing WordPress on the root level of the domain that a password protected directory would return a 404 page instead of the typical login box.

The problem comes from the Apache rewrite engine that WordPress uses to make search engine friendly URL’s. WordPress uses a .htaccess file in the root folder of the install to take any URL and allow WordPress to process and serve the appropriate page, or error.

(more…)

How To Create a Custom 404 File Not Found Page

January 20th, 2010

One major design element often overlooked by web developers is their 404 File Not Found error page. Most our focus gets lost on CSS and XHTML validation that we often overlook what happens when something goes wrong. Even these pages should be styled with the individual touches of the website. Effective 404 error pages communicate why a particular page couldn’t be displayed and what users can do next.

Who wants their users to see the dreaded default 404 page:

Creating your own custom 404 File Not Found Page can be done in three simple steps by creating or modifying the .htaccess file of the directory and placing a 404.html file in the same directory.

(more…)