Archive for : December, 2010

Magento – save and get data from cache

Just a method to save and get data from magento cache


$mydataforcache = "My data for cache";
$cache_name = "maycachename";
$CACHEDATA = MAGE::app()->loadCache($cache_name);
if (isset($CACHEDATA) && ($CACHEDATA != ""))
{
// Use data
echo $CACHEDATA;
}
else
{
// Save data to cache
Mage::app()->saveCache($mydataforcache, $cache_name, array(), 10800);
}

Javascript – compare two dates

Compare two dates in Javascript:


<html>
<head>
<title>JavaScript - compare two dates</title>
</head>
<body>
<script language="Javascript" type="text/javascript">
var date1 = new Date("22/12/2010");
var date2 = new Date("25/12/2010");
if (date1 <= date2)
{
alert("Date 1 lower or equal than date 2!");
}
else
{
alert("Date 2 lower than date 1!");
}
</script>
</body>
</html>

Zend Framework – Setting the DocType

Specify the DocType


$this->doctype('XHTML1_STRICT');

XHTML1_STRICT – XHTML 1.0 Strict

XHTML1_TRANSITIONAL – XHTML 1.0 Transitional

HTML4_STRICT – HTML 4.01 Strict

HTML4_Loose – HTML 4.01 Loose

HTML5 – HTML 5

Source: Zend Framework

Javascript get elements by name

Javascript get elemens by name:


<html>
<head>
<script type="text/javascript">
function getInputValues(varName)
{
varValues = document.getElementsByName(varName);
for (var i = 0; i < varValues.length; i++)
{
alert(varValues[i].value);
}
}
</script>
</head>
<body>
<input type="text" name="xName" ><br />
<input type="text" name="xName" ><br />
<input type="text" name="xName" ><br />
<input type="button" onclick="getInputValues('xName'); return false;" value="Display Values">
</body>
</html>

Javascript redirect to another page

Javascript redirect to another page


window.location = "redirect url";

Javascript – confirm leave the page

Javascript code to be used when you need a confirmation before leaving a page:


<script language="javascript" type="text/javascript">
window.onbeforeunload = confirmClose;
function confirmClose(){
return "Are you sure do you want to leave this page.";
}
</script>

MySQL show tables from a database

MySQL command to view all tables from a database:


SHOW TABLES;

MySQL command to view databases from server

MySQL command to view databases from server:


SHOW DATABASES;

MySQL – show user privileges

MySQL command to view user privileges:


SHOW GRANTS FOR 'root'@'localhost';