Tag Archives: php

MySQL: Count the total occupancy rate for a time period (month)

Recently I encountered a somewhat interesting MySQL/PHP task: determine occupancy for a reservation system. This entailed determining how many reservation days fall within a particular month. It was not possible to simply determine each reservation length (datediff from/to) and sum them because some reservations started before the month in question and other reservations lasted until the month was over. Therefore, one solution is to get the reservation lengths then compare the start and end of the reservation to the start

Reverse order of individual items in a delimited string

Topic: Reversing the order of individual items in a string. Specifics: I had a date contained in a GET query string that was formatted as follows: 01/27/2013 and I needed it reversed to 2013/01/27 Here is a simple method to do the reversing in PHP: $toDate = htmlentities($_GET[‘to’]); $toDateNew = implode(“/”,(array_reverse(explode(“/”,$toDate)))); Explanation of code: First you explode the $toDate variable, then reverse the resulting array, finally you implode that array back into a string. Of course there are other date

Set your own date format in MySQL

Use DATE_FORMAT in MySQL to create your date strings formatted however you like: SELECT CONCAT(YEAR(res_hotel_booking_bookings.created),’-‘,DATE_FORMAT(res_hotel_booking_bookings.created,’%m’) ,’-‘,DATE_FORMAT(res_hotel_booking_bookings.created,’%d’)) AS creationDate, Count(res_hotel_booking_bookings.id) As reservationsMade FROM res_hotel_booking_bookings WHERE res_hotel_booking_bookings.created >= ‘2013-10-15 00:00:00’ AND res_hotel_booking_bookings.created <= ‘2013-10-17 24:00:00’ GROUP BY YEAR(res_hotel_booking_bookings.created), MONTH(res_hotel_booking_bookings.created), DAY(res_hotel_booking_bookings.created) ORDER BY creationDate DESC There are more concise ways to do this, but this was adapted from an earlier method that used CONCAT so I stuck with that… 🙂

Changing the php file upload limit in Funtu Linux

To increase the PHP upload limit on a Funtoo based server, I needed to adjust these two settings in php.ini: php_value upload_max_filesize 15M php_value post_max_size 15M More related resources: upload – Changing upload_max_filesize on PHP – Stack Overflowhttp://stackoverflow.com/questions/1122418/changing-upload-max-filesize-on-php<?php ini_set(‘upload_max_filesize’, ’10M’); echo ini_get(‘upload_max_filesize’), “, ” , ini_get(‘post_max_size’) I end up with: Changing the php file upload limit in Ubuntu Linux | miscellaneous.debrishttp://www.miscdebris.net/blog/2008/04/14/changing-the-php-file-upload-limit-in-ubuntu-linux/sudo nano /etc/php5/apache2/php.ini search for “upload_max_filesize” with Ctrl-W and change “2M” to “20M”. Save the file with Ctrl-O and exit…

How to fix Customized Recent Comments duplicate comments

Customized Recent Comments is a great plugin for displaying recent comments on your WordPress blog. It has all the features I need and requires minimal install and setup. With most ‘recent comments’ plugins/widgets, if you (the blog owner) respond to a bunch of comments at once, you end up having your comments take up the entire recent comments listing 🙁 Thankfully, one of my favorite features of the plugin is its ability to exclude particular commenters from being listed. 🙂 However, the only issue I have

Make Windows 7 fulltext search PHP documents

Recently while trying to find the PHP file that I needed to edit, I was once again frustrated by Windows seeming inability to search the text contained in PHP files 🙁 Windows obviously has the capability to do file content searches since it does so for .txt files. Finally I got fed up with it and decided to find out how to enable full text searching of .php documents. Here is what worked for me, I hope you will find

Building a random name generator

Last night I had fun building a  little random name generator for my friend Adam and my wife. They both write and sometimes it is difficult to come up with names for characters, that is where the new tool comes in handy: Character Name Generator Every time you refresh the page you get a new name 🙂 I used to code a lot of fun little projects like this but lately I have not made time for it. I do

Fixing Warning: date() [function.date] in PHP 5.3 [solved]

If you recently upgraded to a newer version of PHP, like PHP 5.3, you may be getting some errors similar to this in your PHP scripts: Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Chicago’ for […]  instead