Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog.

Archive for May, 2008

mysql temporary tables

Posted by chris on May 28th, 2008 Comments(0)

Temporary tables exist in memory and are great if you just want to create a quick data store for the life of your current database connection. MySQL will purge the temporary table from memory at the end of the database connection. For a temporary table that persists and can be used by multiple connections you will need to create a Heap table.

1
2
3
CREATE TEMPORARY TABLE cancelledOrders
			ENGINE=MEMORY 
SELECT * FROM my_table

More information on temporary and heap tables

In SQL ()

modifying tables using javascript and dom

Posted by chris on May 27th, 2008 Comments(0)
1
2
3
4
5
6
var tbl = document.getElementById('table');
var row = tbl.getElementById('tr');
var cell = row.getElementsByTagName('td');
cell[0].innerHTML='cell 0';
cell[1].innerHTML='cell 1';
cell[2].innerHTML='cell 2';
In ajax/dom/javascript ()

use linux screen command to manage multiple shell sessions

Posted by chris on May 27th, 2008 Comments(0)

Screen is useful for running a script or other long process as yourself if you are worried about disconnecting from your SSH session or want to do some other things in the shell as the process runs. You will need screen installed to do this. This will really save you a lot of time with Linux servers.

To start a screen session:

screen -R -D

To detatch from the screen session and continue working from the shell:

Ctrl + a + d

To view the status of your screen sessions:

screen -ls

To reattach an existing screen session:

screen -r screen name

You can get the screen name via the screen -ls command, the screen name should look something like 3003.pts-4.localhost.

In linux ()

mysql date/time functions

Posted by chris on May 12th, 2008 Comments(0)

Better than using PHP to time format date times stored in your database for easier human readability is using MySQLs built in functions:

To turn a date time stamp into a readable time on the 12 hour clock with an AM/PM signifier
TIME_FORMAT(date_time,’%h:%I:%l %p’) as time

Returning just the date time portion of date time stamp
DATE(date_time) as date

Make a date pretty
Unlike the actual dates I go on, in MySQL you can actually make her pretty, the following code would convert 2008-01-01 into Jan 01, 2008.
DATE_FORMAT(tour.date_time,’%b %d, %Y’) as date

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

In SQL ()