Get data from Interval of Dates

SELECT * FROM TableName where Date => '2012/10/11'
and Date <= '2012/12/21'

Here we can get datas from StartDate(‘2012/10/11’) to EndDate(‘2012/12/21’)


Select record has highest “Date”(any field)

You can select record corresponding to its highest value in any field

SELECT * FROM tableName where fieldName = (SELECT MAX( fieldName ) FROM tableName)


SELECT MAX( fieldName ) FROM tableName

Get the Highest in fieldName. It can be number or date(In this “2014-02-30 12:20:12” format).

MAX( fieldName ), does the Magic….;)

Download JSON as CSV file

Download a JSON in CSV file

var data = [["name1", "city1", "some other info"], ["name2", "city2", "more info"]];
var csvContent = "data:text/csv;charset=utf-8,";
data.forEach(function(infoArray, index){

   dataString = infoArray.join(",");
   csvContent += index &lt; infoArray.length ? dataString+ "\n" : dataString;


var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");; // This will download the data file named "my_data.csv".

Export data in DB as CSV file (Store in system / Send it to Mail)

Export data in DB as CSV file (Store in system / Send it to Mail)

function query_to_csv($db_conn, $query, $filename, $attachment = false, $headers = true) {

if($attachment) {
// send response headers to the browser
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename='.$filename);
$fp = fopen('php://output', 'w');
} else {
$fp = fopen($filename, 'w');

$result = mysql_query($query, $db_conn) or die( mysql_error( $db_conn ) );

if($headers) {
// output header row (if at least one row exists)
$row = mysql_fetch_assoc($result);
if($row) {
fputcsv($fp, array_keys($row));
// reset pointer back to beginning
mysql_data_seek($result, 0);

while($row = mysql_fetch_assoc($result)) {
fputcsv($fp, $row);


// Using the function
$sql = "SELECT * FROM table";
// $db_conn should be a valid db handle

// output as an attachment
query_to_csv($db_conn, $sql, "test.csv", true);

// output to file system
query_to_csv($db_conn, $sql, "test.csv", false);