In some cases we need to remove old entries from the database or remove entries before specific days. So mysql provides the syntax to delete records:

 DELETE FROM $table_name WHERE $date_field < date_sub(CURDATE(), $numberOfDays day)
If above query does not work for you then its version issue. So you can do same thing like this:
  DELETE FROM $table_name WHERE DATEDIFF(CURDATE(), $date_field) >= $numberOfDays

 

In php we have a function to replace nl2br means new line to break format. but when we need this functionality in our javascript code then what we do? We can do by simply manner: function nl2br(value) { return value.replace(/\n, ""); } Above function will return the converted '\n' to ''. But above function has a disadvantage. It convert only first line of the value. We can convert all new lines to break format with below function: function nl2br(value) { ...

 

If customer is logged in on site and you want to get all information of that customer then you can get by below script: if( $customer = Mage::getSingleton('customer/session')->isLoggedIn()) { $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData(); print_r($customerData); } It will show you result in an array format: Array ( [entity_id] => 1 [entity_type_id] => 1 [attribute_set_id] => 0 [website_id] => 1 ...

 

Joomla provides some basic themes which are already installed in the templates folder. When any developer develop the CMS in the joomla , he use his own template with new design. On the index page $this->baseurl works well but when he want to own module then he create a folder in custom template folder. But in that module folder $this->baseurl doesn't work. Why? because joomla does not provide to access $this in the custom module folder. You should replace below code...

 

Numeric validation require in mostly cases when we want that user enter only numeric value in any text field. For example 'Age' field. Obviously, age can not be in string format. function checkNumericValueValidation() { var enteredValue = document.getElementById('numeric_value').value; if (enteredValue == '' || isNaN(enteredValue)) { alert('Ohh! You entered wrong number format.'); } else { alert('Congrates! You entered correct Numeric Value.'); } } Above,...

 

Are you looking for a regular expression to make clickable url in the string? Yes!, you will get your solutions here:


echo preg_replace("/http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "$0", $string);

If you want to open url in new tab then :

echo preg_replace("/http\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/", "$0", $string);

 

Sometimes we written a code to enter some dynamic entry in the table but did not want to enter duplicate records for same id ( not primary field). and we found that we have entered many records in the table and not it is not possible to delete record manually. For this we can run this code CREATE TABLE temp_tbl LIKE tblNameInWhichDuplicateReocrds; INSERT INTO temp_tbl SELECT tblNameInWhichDuplicateReocrds.* FROM tblNameInWhichDuplicateReocrds; DELETE FROM...

 

In most cases we see that when we try to open any site then it add 'www' in the url or remove from the url. This can be manage by Htaccess in general sites on the server. Wordpres provides a good facility to manage this url setting. 1. Go Settings > General 2. Set WordPress address and Site address for your site. 3. Change according your requirement and save this setting. You will see that your domain will redirect according your...

 

In most cases, an user (A developer) need to write own code to generate an order, generate invoice for an order or generate shipment for an order then he need both order id and its increment id. You can get this increment value by following code:

$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('sales/order')->getLastOrderId());
$orderIncrementId = $order->getIncrementId();

 

When I tried to export or import any profile, then I got a fatal error: Fatal error: Call to undefined method Mage_Adminhtml_Block_Abstract::getexceptions() in .......\app\code\core\Mage\Adminhtml\Block\System\Convert\Profile\Run.php on line 167 To remove this problem follow below process: 1. Go to file which showing in fatal error. 2. Comment line 167 and 168, then it will show like: // if (!is_null(parent::getExceptions())) // return...

 

I installed Magento on my local server. When I tried to add new category then I got a fatel error. What I did and what I got: I click on catalog > Manage Categories I got Fatal error: Call to undefined method Mage_Adminhtml_Block_Widget::getrowurl() in .....app/code/core/Mage/Adminhtml/Block/Widget/Grid.php on line 1607 I tried to find out the error reason then I got my solution. And solution is : Go To app/code/core/Mage/Adminhtml/Block/Widget/Grid.php Search function getRowUrl...

 

In most cases we need to upload something on server without refreshing the page. for example we want to upload an image from popup window. But it will refresh the page and we will lost our popup and its content... so for this type of problems we providing an attractive code for upload a files on server through AJAX technology from webtoolkit. File: AIM = { frame : function(c) { var n = 'f' + Math.floor(Math.random() * 99999); var d =...

 

What is the GD library? GD is an open source code library for the dynamic creation of images by programmers. GD is written in C, and "wrappers" are available for Perl, PHP and other languages. GD creates PNG, JPEG and GIF images, among other formats. GD is commonly used to generate charts, graphics, thumbnails, and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve website development. You can learn more from...

 

Many times developer gets the time problem during project development. Because he works on date function which provides by PHP but site works on different server which time is different from developer country. So for this case you can use magento time which priovides by Magento self. It Manage the server time. This line will print the time in string format so you can convert into date format according to your requirement: ...

 

Mostly time we need to create some variables at run time. because we do not want to write same line. For example you have an array like : $user_details = array( 'name' => 'test1', 'email' => 'test@example.com', 'phone_number' => '1234567890' ); and you want to make run time variable like : $name = 'test1'; $email = 'test@example.com'; $phone_number = '1234567890'; Mostly developers do this type of mistake: foreach ( $user_details as $key => $value ) { echo...

 

Sometimes we need to develop a website with Hindi font. But main problem is how to insert content in Hindi in admin panel. so here is a solution by this admin can enter content in Hindi font. It will work like: When admin type any word like 'welcm' and then type space it will automatically convert into 'वेलकम' Translate English to Hindi google.load("elements", "1", { packages: "transliteration" }); function onLoad()...

 

In most cases we need to get the current logged in user information like his/her email address, Id, any other attributes value. then we can get this by below code :

//Customer Email 
Mage::getSingleton('customer/session')->getCustomer()->getEmail());

// Customer First name
Mage::getSingleton('customer/session')->getCustomer()->getFirstName());

And also we can find the custom attribute values.