2013년 8월 17일 토요일

jquery tablesorter module

github url : https://github.com/Mottie/tablesorter

사용방법

[html]
<script type="text/javascript" src="jquery.tablesorter.min.js"></script>
<link rel="stylesheet" href="theme.blue.css" />

<table id="myTable> <tr> <th>No</th> <th>Grade</th> <th>Price</th> </tr> <tr> <td>1</td> <td>C</td> <td>$0.50</td> </tr> <tr> <td>2</td> <td>B</td> <td>$3.75</td> </tr> <tr> <td>3</td> <td>G</td> <td>$1.5</td> </tr> <tr> <td>4</td> <td>F</td> <td>$12.0</td> </tr> <tr> <td>5</td> <td>A</td> <td>$10.5</td> </tr> </table>



<script>

$(function(){ $("#myTable").tablesorter({ theme : 'blue', widgets : ['zebra', 'columns'], usNumberFormat : false, sortReset : true, sortRestart : true, headers: { 0: { sorter : false } } }); });
</script>

커피 브로잉가이드 - 핸드드립

커피 브로잉가이드 - 프렌치프레스

커피 브로잉가이드 - 모카포트

커피 브로잉가이드 - 사이폰

커피 브로잉가이드 - 더치

커피 브로잉가이드 - 커핑 cupping

2013년 8월 8일 목요일

mysql db schema dump php script

<?php
// Delete the tables if they exists?
$drop = true;
$dumpdata = false;

$user = 'user';
$passwd = 'password';
$host = '127.0.0.1';
$port = 3306;
$db = 'dbname';
db($host, $user, $passwd, $db, $port, $drop, $dumpdata);

function db($host, $user, $passwd, $db, $port, $drop, $dumpdata) {
    // DB Connection
    $mysqli = new Mysqli($host, $user, $passwd, $db, $port);
    if($mysqli->connect_error) die("Can't connect to MySql server: " . $mysqli->connect_errno .' => '. $mysqli->connect_error);
    $mysqli->set_charset('utf8');
    // Search the table in the database
    $tables = array();
    $query = "SHOW TABLES FROM $db;";
    $rs = $mysqli->query($query, MYSQLI_STORE_RESULT) or die("Can't execute the query: ".$mysqli->error);
    while ($row = $rs->fetch_array(MYSQLI_NUM)){
            $tables[] = $row[0];
    }
    // Create the header archive
    $info['date'] = date("d-m-Y");
    $info['time'] = date("h:m:s A");
    $info['mysqlver'] = $mysqli->server_info;
    $info['phpver'] = phpversion();
    print_r($info);
    // Dump variable
    $dump= "";
    foreach ($tables as $table){
        $drop_table_query = "";
        $create_table_query = "";
        $insert_into_query = "";
        // Start the query that create the db.
        if ($drop){
                $drop_table_query .= "DROP TABLE IF EXISTS `$table`;" . PHP_EOL;
        } else {
                $drop_table_query .= "# No specified." . PHP_EOL;
        }
        $query = "SHOW CREATE TABLE $table;";
        $rs = $mysqli->query($query, MYSQLI_STORE_RESULT) or die("Can't execute the query: ".$mysqli->error);
        while ($row = $rs->fetch_array(MYSQLI_NUM)){
                $create_table_query .= $row[1].";";
        }
        // This query insert the datas.
        $query = "SELECT * FROM $table;";
        $rs = $mysqli->query($query, MYSQLI_STORE_RESULT) or die("Can't execute the query: ".$mysqli->error);
        while ($row = $rs->fetch_array(MYSQLI_NUM)){
                $columns = array_keys($row);
                foreach ($columns as $column){
                        if ( gettype($row[$column]) == "NULL" ){
                                $values[] = "NULL";
                        } else {
                                $values[] = "'".$mysqli->real_escape_string($row[$column])."'";
                        }
                }
                $insert_into_query .= "INSERT INTO `$table` VALUES (".implode(", ", $values).");" . PHP_EOL;
                unset($values);
        }
    $dump .= "# | Empty Table '$table'" . PHP_EOL;
    $dump .= "# +------------------------------------->" . PHP_EOL;
    $dump .= $drop_table_query . PHP_EOL;
    $dump .= PHP_EOL;
    $dump .= "# | Structure of table '$table'" . PHP_EOL;
    $dump .= "# +------------------------------------->" . PHP_EOL;
    $dump .= $create_table_query . PHP_EOL;
    $dump .= PHP_EOL;
    if($dumpdata) {
        $dump .= "# | Data loading of table '$table'" . PHP_EOL;
        $dump .= "# +------------------------------------->" . PHP_EOL;
        $dump .= $insert_into_query . PHP_EOL;
        $dump .= PHP_EOL;
    }
    }
    createdumpfile($dump, $db);
    $mysqli->close();
}
function createdumpfile($dump, $db) {
    $myFile = $db.'.sql';
    // if the backup exists we delete and rewrite it
    if (file_exists($myFile)){
    unlink($myFile);
    }
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $dump);
    fclose($fh);
}