Posts Tagged "PHP"

Get last order of an customer magento

Here is the example code by which you can get last order details into mangento of using email id. $_customer = Mage::getModel('customer/customer'); $_customer->loadByEmail('demo@demo.com'); $orders = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') ->addFieldToFilter('customer_id', $_customer->getId()) ->addAttributeToSort('created_at', 'DESC') ->setPageSize(1); <strong>ID</strong> echo $orders->getFirstItem()->getId(); Shashi Dhar KumarShashi Dhar Kumar Experience in Web/software development including client server and implementation using PHP, XML, MySQL and SQL Server. Experience of working on Apache, Linux projects, Javascript, Ajax, Putty, FTP, Remote Connection, XML parsing, Mod-Rewriting, Payment Gateways and shipping modules, Trouble shooting and…

Read More

How you can add Cron Job at Cpanel?

Execute Cron Job in Cpanel using PHP script. In cpanel the following will also work: Execute code every minute(Server Time) using following code: * * * * * php -q /home/serverpath/file.php Execute code every five minute(Server Time) using following code: */5 * * * * php -q /home/serverpath/file.php Execute code twice an hour(Server Time) using following code: 0,30 * * * * php -q /home/serverpath/file.php Execute code once an hour(Server Time) using following code: 0 * * * * php…

Read More

How to export the data from MySQL into a XML file with PHP?

There are a couple of ways to export data from MySQL to a XML file. This post looks at how to export the data from MySQL into a XML file with PHP. The example code below uses the raw mysql_* functions but it should be easy enough to substitute a database library’s functions instead. It also writes the data out line by line to the XML file whereas you could buffer the whole file in memory and write it out…

Read More

How to export the data from MySQL into a CSV file with PHP including a header row?

There are a couple of ways to export data from MySQL to a CSV file but some of them never supports adding a header row to the CSV which contains the column names. This post looks at how to export the data from MySQL into a CSV file with PHP including a header row. The example code below uses the raw mysql_* functions but it should be easy enough to substitute a database library’s functions instead. It also writes the…

Read More

Capitalize the sentence in Javascript!

Capitalize the sentence in Javascript! <script type="text/javascript" language="javascript">// <![CDATA[ String.prototype.capitalize = function(){ return this.replace( /(^|s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); } ); }; function capWords() { var inputString = document.form1.instring; // The input text field var outputString = document.form1.outstring; // The output text field outputString.value = inputString.value.capitalize(); } // ]]></script> Shashi Dhar KumarShashi Dhar Kumar Experience in Web/software development including client server and implementation using PHP, XML, MySQL and SQL Server. Experience of working on Apache, Linux projects, Javascript, Ajax, Putty,…

Read More

How to add custom post type in wordpress

Open “function.php” add the following code to add new custom post type : <?php add_action(‘init’, ‘featured_post_register’); function featured_post_register() { $labels = array( ‘name’ => _x(‘Featured Posts’, ‘post type general name’), ‘singular_name’ => _x(‘Featured Posts’, ‘post type singular name’), ‘add_new’ => _x(‘Add New’, ‘featured posts’), ‘add_new_item’ => __(‘Add New Featured Posts’), ‘edit_item’ => __(‘Edit Featured Posts’), ‘new_item’ => __(‘New Featured Posts’), ‘view_item’ => __(‘View Featured Posts’), ‘parent_item_colon’ => ” ); $args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ =>…

Read More

301 redirect with htaccess

How to redirect web based page with .htaccess Following are the code to paste (be careful to write on .htaccess it can be messed up whole website if anything goes wrong) into .htaccess file 301 redirection for any domain : RewriteEngine On RewriteCond %{HTTP_HOST} !^www.olddomain.com RewriteRule ^(.*)$ http://www.newdomain.com [R=301,L] newdomainRewriteRule ^$ http://www.newdomain.com [R=301,L] RewriteRule ^index.htm$ http://www.newdomain.com [R=301,L] RewriteRule ^index.php$ http://www.newdomain.com [R=301,L] RewriteRule ^index.html$ http://www.newdomain.com [R=301,L] RewriteRule ^index.shtml$ http://www.newdomain.com [R=301,L] RewriteRule ^index.asp$ http://www.newdomain.com [R=301,L] RewriteRule ^default.asp$ http://www.newdomain.com [R=301,L] RewriteRule ^index.aspx$ http://www.newdomain.com…

Read More

Default page name for technology used in Internet

Following are the detault pages for website of technology based : 1) HTML Based default pages : a) index.htm b) index.html c) default.htm 2) PHP Based default pages : a) index.php 3) SHTML Based default pages : a) index.shtml 4) Classic ASP Based default pages : a) index.asp b) default.asp 5) .Net(Framework) Based default pages : a) index.aspx b) default.aspx 6) Coldfusion Based default pages : a) index.cfm 7) CGI/Perl Based default pages : a) index.pl b) default.pl Shashi Dhar…

Read More

Get the First Monday of the current Month or Get Last Day of Month or Get First Day of Month

Get the First Monday of the current Month or Get Last Day of Month or Get First Day of Month Get the First Monday of the current Month <?php function getFirstMonday($month,$year) { $num = date(“w”,mktime(0,0,0,$month,1,$year)); if($num==1) return date(“Y-M-ds”,mktime(0,0,0,$month,1,$year)); elseif($num>1) return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(8-$num))); else return date(“Y-M-d”,mktime(0,0,0,$month,1,$year)+(86400*(1-$num))); } $month = date(“m”); $year = date(“Y”); // this will output current month’s First Monday echo getFirstMonday($month,$year); ?> Get the Last Day of current Month <?php echo date(‘d/m/y’,strtotime(“last Friday”,mktime(0,0,0,date(“n”)+1,1))); // you can replace your Day instead…

Read More

Get file name and remove file extension using php

Get a File name from url Using PHP Get the “filename”, or the last part of the string, with the basename function. <?php $url = ‘http://www.example.com/feeds/xyz/index.php?filename=abc’; echo basename($url); // print “index.php”; ?> Remove a File Extention Using PHP To strip the file extension from a file name you can use the combination of strrpos() and substr() function like this : <?php $fileName =”index.php”; $name = substr($fileName, 0, strrpos($fileName, ‘.’)); echo $name; //print “index” ?> Shashi Dhar KumarShashi Dhar Kumar Experience…

Read More