This snippet will get the filename from the url. The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then
file.html is the file name.
This snippet will get the filename from the url. The filename is the last part of the URL from the last trailing slash. For example, if the URL is http://www.example.com/dir/file.html then
file.html is the file name.
Chrome Experiments is a website which show cases Javascript experiences from a range of different developers. Many are cutting edge, some are just plain cool and a bundle of fun. They certainly show what can be achieved with the wonders of Javascript. Chrome Experiments is a Google website and anyone can submit an experiment.
Get Cool Javascript Tricks at Chrome Experiments LinkSmashing Magazine's excellent competition for creating a resume (CV) for a fictional web designer. The result is a collection of beautifully presented CV's. Great inspiration for the next time you need to update your CV!
Get Create a webdesign CV LinkIt is a good idea to block access to .svn directories if you are using Subversion. Otherwise, anyone can read the files. Add the following snippet to your .htaccess file (in root directory of the website).
See Block access to .svn directories using htaccess SnippetExample usage - if a field is a varchar and you need to sort by a number. It will sort it alpabetically, instead of numerically. Type casting will convert it to an altenative data type.
See MySQL Type Casting SnippetHere is an example of how to select some data from a table on one database and insert into a table of a different database. I assumes that you are using the same mysql connection.
The MySQL USE command is used to select the appropriate database at the appropriate time. database1 is where the data is being selected from and database2 is where it is inserted to.
See Select from a database and insert into a different database SnippetSimple command to gzip a file.
See GZip a file SnippetModify an existing column to make it auto increment.
See Make an existing MySQL column auto_increment SnippetBackup a database from cron. Add the following to the cron tab.
See Backup MySQL Database from Cron SnippetBasic while loop. It selects everything from a table called "table1" and then loops through each row. On each iteration, you can do something with the value for a specficied field. In this case, we echo out the values of the id and "anotherfield" fields.
See PHP While Loop SnippetThis is for the basic snippet to connect to a MySQL database.
See MySQL connect to database SnippetAdd new user to MySQL database. First, log into the MySQL console, and then run the following command, replacing databasename, username and password.
See Add new user to MySQL database SnippetSimple command to backup a MySQL database. Run from Linux command line.
See MySQL Dump (backup) SnippetThis is the command to restore a MySQL database.
To restore it on a local computer, follow this process:
1) Open the command line (Windows, Linux or Mac)
2) cd (change directory) to the directory where the mysql.exe is located. This is likely to be in a bin directory. For example, with WAMPserver, mysql.exe is located here:
c:\wamp\bin\mysql\mysql5.0.45\bin
3) Create the database (if you haven't already). You can use phpmyadmin for this if you wish
4) Copy the dump or sql file to the directory located in step 2
5) Run the command in the following snippet
I have just discovered a conflict between Skype and WampServer that I thought I would share. They both use port 80 which causes the conflict. If you run Skype before running Wamp, then Apache will not run. If you go to a site on localhost, you will probably get a blank screen.
The solution is pretty simple. Just make sure you start all services on WAMP before you open Skype. If Skype is disconnected it will work fine. You can then connect Skype once Wamp is running.
Read WAMP and Skype ConflictThe MySQL Server has gone away error can happen when trying to restore a database. There are a few possible causes for this and one of the most likely is that the database is very big in size and the packet size in MySQL is not big enough.
Read MySQL Server Has Gone Away Error - Cause & SolutionIf you are running WampServer on your local machine, it can be a bit tricky to restore a MySQL database. You need to do it from the Windows command line (DOS prompt), rather then the MySQL console command line. The actual MySQL restore command is slightly different to normal and you need to make sure you are in the right directory first.
Read Restore MySQL database in WampServerCopying an entire directory in FreeBSD (a Unix based operating system similar to Linux) is very easy.
The following example is to copy a directory on a web server. Firstly, you must create the destination directory.
Go to the parent directory and run the following command:
This will create a directory inside the parent directory. Replace DESTINATIONDIRECTORYNAME with a directory name of your choosing.
Next, run the command to copy all of the files from the source directory into the destination directory.
Read Copy an entire directory in FreeBSDIt is often the case that a column such as the ID column on a table will auto increment. This simply means that the next insert into the table will have an ID that is one more then the previous one and therefore all ID's will be unique.
However, if you delete a row from the table, the table will auto increment as if the row had not been deleted at all. The result is a gap in the sequence of numbers. This is normally not that much of an issue, but you may want to reset the auto increment field.
There are two simple steps in resetting an auto increment field:
Read Reset auto increment after deleting a table rowThe mere mention of the word backup makes many website owners panic. "Backup! Um, yeah well I meant to do backups, but I never get around to it". Trust me, when a database fails you need a recent backup. And databases do fail!
There are many scripts available online that can run backups for you automatically. The one problem with most of them is that they can time out if the database is too big.
The alternative is to run a bash script on cron. A what on what you might ask! Don't panic!
Read Backup MySQL Database from Cron Automatically