VV's Corner
my collection of random thoughts, how-to's and code snippets
RSS
  • About

Selecting a random row using MySQL

By vinoaj On July 25, 2007 · Add Comment
There are many examples where you would need to retrieve a random record or more from a set of tables. For example your page template may be cycling through QOTDs, testimonials, offers, specials, and so forth. To retrieve a random row in MySQL, use the ORDER BY RAND() statement to randomly order the rows of [...]
[Continue Reading...]

PHP code snippet – Reorder items in a table

By vinoaj On July 9, 2007 · Add Comment
This snippet of code reorders items in a table based on the number of steps you want to move an item from its current position. It moves the item of interest to its new position and shifts all other items to their new shifted positions. PLAIN TEXT PHP: function moveItem ($n_steps) { if ($n_steps == [...]
[Continue Reading...]

svn – Ignore/exclude files from version control

By vinoaj On July 5, 2007 · Add Comment
In most projects there are going to be files that you wish to ignore in version control. These could be temporary files, log or debug files, and so forth. These are files that you can safely ignore when executing commands such as svn commit and svn st. The following shows how to configure your svn [...]
[Continue Reading...]

Class Inheritance in Javascript

By admin On June 5, 2007 · Add Comment
My previous post showed how to create classes in Javascript. This addendum post shows how to create an inherited class from a parent class. The concept is simple. Declare and define your parent class Declare and define your child class without defining the parent-child relationship Add a new instance of your parent class to your [...]
[Continue Reading...]

Creating classes with Javascript

By admin On June 5, 2007 · Add Comment
Javascript is a prototype-based language rather than a class-based language (e.g. Java). For an explanation of the difference, see Mozilla's comparison of class-based and prototype-based languages. In short, in a class-based language, objects are created by instantiating classes. The classes' list of properties and methods cannot be altered (e.g. added to) at runtime. A prototype-based [...]
[Continue Reading...]

Akismet and PHP for your site

By admin On May 15, 2007 · Add Comment
A few sites I administer have recently had the misfortune of having spambots visit their enquiry and contact pages. These pages usually have a contact form, where an enquirer can leave their name, e-mail, and request or comment. When they submit the form, a copy of the message is e-mailed to the site owner. The [...]
[Continue Reading...]

Timezones and UTC in PHP

By admin On May 9, 2007 · Add Comment
If you are dealing with multiple users in different timezones or simply want to display times in a timezone other than your server's settings, it is best to store timestamps as their UTC (~ GMT) equivalents. When you read those timestamps later, you can convert them to local time. Local time to UTC time PLAIN [...]
[Continue Reading...]

HTTP Status Codes

By admin On May 6, 2007 · Add Comment
The following is a list of HTTP Status Codes returned by a web server and what they mean. The information is summarised from RFC2616 Section 10. Informational 1xx Informational responses that contain no message bodies. 100 Continue - The client should continue with the request. Either the request is in a queue or the client [...]
[Continue Reading...]

Prevent caching of page on client’s end – PHP and HTML solutions

By admin On May 6, 2007 · Add Comment
To prevent the caching of a web page on your client's end, use the following snippet of PHP to ensure that the appropriate HTTP headers are sent. PLAIN TEXT PHP: header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Tue, 03 Jul 1979 00:00:00 GMT");   // Date in the past The first header tells the client that the [...]
[Continue Reading...]

Using mysqldump to export a database

By admin On April 28, 2007 · Add Comment
mysqldump is a useful utility for dumping the contents of an entire database to an SQL file. PLAIN TEXT CODE: mysqldump --user=dbusername --password=dbpassword db_name_here> db_name_here.sql By default the --opt option is enabled, which is a shorthand option for specifying the below options. According to the documentation, using this option "... should give you a fast [...]
[Continue Reading...]
← Previous Entries Next Entries →
  • Recent Posts

    • Getting started with Google Geo (Maps, Mapplets & Earth) APIs
    • User-friendly 404 pages
    • Using the Google Static Maps API to include maps in your emails
    • Python: Inserting characters into a string
    • Python: removing repeated values in a list
  • Tags

    adwords analytics api auto-tagging autotagging earth gclid geo google google maps api static google webmaster tools 404 widget list mapplets maps python regex regular expressions set street streetview string view
  • Share
  • About
Build a website with PageLines