Print MySQL Query
33
Simple upload class with features such as
- Upload of multiple files at the same time.
- Filtering uploads by size and extension.
- Uploads to configurable subdirs based on date.
- Automatic file renaming if a file with the same name exists.
- Transloading. Copying files from a different host to the local host. (Like Imageshack does)
- And more...
- Upload of multiple files at the same time.
- Filtering uploads by size and extension.
- Uploads to configurable subdirs based on date.
- Automatic file renaming if a file with the same name exists.
- Transloading. Copying files from a different host to the local host. (Like Imageshack does)
- And more...
28
Create a Thumbnail
26
This is a simple function to generate a random ID of letters and numbers however long you want. All you do is pass it how many parts you want and then how many pieces(chars/numbers) per part you want.
I hope you enjoy
I hope you enjoy
24
"Today in the news, MySQL previews..."
As a "preview" of text, this MySQL select will return the first few words out of a text field in a database. It returns entire words (doesn't cut them off in the middle) and follows the last word with an elipse "..."
In the PHP, assign $CharactersToDisplay to a number - the approximate number of characters desired (or you can hard-code it if you want).
For the example, I also use $TheID as the row identity for the record to display.
As a "preview" of text, this MySQL select will return the first few words out of a text field in a database. It returns entire words (doesn't cut them off in the middle) and follows the last word with an elipse "..."
In the PHP, assign $CharactersToDisplay to a number - the approximate number of characters desired (or you can hard-code it if you want).
For the example, I also use $TheID as the row identity for the record to display.
24
This is a PHP and JavaScript Image gallery that I created. There are 2 uses for this.
1.) You can save it as index.php and place in a folder containing images and it will display the images in that folder.
Example:
place index.php in images/folder
http://yoursite.com/images/folder/
This will display all images in that folder
2.) Pass in the path to the folder to display in the url
Example:
Save as imagegallery.php
http://yoursite.com/imagegallery.php?path=images/folde
1.) You can save it as index.php and place in a folder containing images and it will display the images in that folder.
Example:
place index.php in images/folder
http://yoursite.com/images/folder/
This will display all images in that folder
2.) Pass in the path to the folder to display in the url
Example:
Save as imagegallery.php
http://yoursite.com/imagegallery.php?path=images/folde
23
Get the Size of a Folde
23
This snippet originally is used for targetting ads banners depended on the geographic location of the visitor, but can be used for other purposes. Also originally is used for US and the rest of the world, but you can add check for other countries too.
21
A quick and simple function to dump a variable (array, object, string, int, etc) out into -formatted output for a web browser.
If the variable is an array or an object, you can have it returned into the another variable for later processing (i.e., through templates or e-mail). Due to lack of free time, if the variable is not an array or an object, it will ignore the $return value and print directly to output.
Future revisions will add the above mentioned functionality.
If the variable is an array or an object, you can have it returned into the another variable for later processing (i.e., through templates or e-mail). Due to lack of free time, if the variable is not an array or an object, it will ignore the $return value and print directly to output.
Future revisions will add the above mentioned functionality.
21
If you've ever wanted to build an application that can both find the distance between two zip codes, and find zip codes within a specific radius of another zip code, then this is the snippet for you.
I've tried to build this before using PHP4 and MySQL 4 and have found it to be painfully slow for a one-user connection over a Local Area Network (LAN). So, before you continue reading, I must make it abundantly clear that this method requires PHP 5 and MySQL 5.
This is because in PHP5, we will need the MySQL-Improved interfaces, and in MySQL 5, we will need functions and procedures.
Using functions and procedures in MySQL puts the weight of the calculations on MySQL, where they will run hundreds of times faster than if PHP were to attempt to do the work. In addition, using functions and procedures is still hundreds of times faster than carefully crafted SQL statements (one benchmark took over 10 seconds using a WHERE clause, while the function + procedure method took around .12 seconds--note the dot).
Since I am not a mathematician by trade, I found the necessary calculations using Google.
For the "Great Circle Distance" formula, I used Meridian Word Data's website. For the radius finder, I used another that unfortunately I do not have off the top of my head right now. I will look for it again and repost it for proper accreditation.
For the zip code database, I am using the free zip code database from CFDynamics.
Below, you will find the database and table schema, the functions and procedures, and also a demo PHP script to see all of this put into action. As a courtesy, you may download a dump of this database from my website. It's uncompressed size is 3.4M, and it's compressed size is 537K. The checksum is available here.
Please leave me comments, suggestions, questions, and/or rants about this snippet. I feel this is a very useful bit of code, and hope that others out there may find as much use from it as I will be.
I've tried to build this before using PHP4 and MySQL 4 and have found it to be painfully slow for a one-user connection over a Local Area Network (LAN). So, before you continue reading, I must make it abundantly clear that this method requires PHP 5 and MySQL 5.
This is because in PHP5, we will need the MySQL-Improved interfaces, and in MySQL 5, we will need functions and procedures.
Using functions and procedures in MySQL puts the weight of the calculations on MySQL, where they will run hundreds of times faster than if PHP were to attempt to do the work. In addition, using functions and procedures is still hundreds of times faster than carefully crafted SQL statements (one benchmark took over 10 seconds using a WHERE clause, while the function + procedure method took around .12 seconds--note the dot).
Since I am not a mathematician by trade, I found the necessary calculations using Google.
For the "Great Circle Distance" formula, I used Meridian Word Data's website. For the radius finder, I used another that unfortunately I do not have off the top of my head right now. I will look for it again and repost it for proper accreditation.
For the zip code database, I am using the free zip code database from CFDynamics.
Below, you will find the database and table schema, the functions and procedures, and also a demo PHP script to see all of this put into action. As a courtesy, you may download a dump of this database from my website. It's uncompressed size is 3.4M, and it's compressed size is 537K. The checksum is available here.
Please leave me comments, suggestions, questions, and/or rants about this snippet. I feel this is a very useful bit of code, and hope that others out there may find as much use from it as I will be.
21
Proper Paragraphs









