Friday, 1 April 2016

export database table php

export database table php

Sometime there is need to export database table by php code. There is a very simple approach to do this.   ]export database table by php
export database table by php
/*******EDIT LINES 3-8*******/
$DB_Server = "localhost"; //MySQL Server    
$DB_Username = ""; //MySQL Username     
$DB_Password = "";             //MySQL Password     
$DB_DBName = "";         //MySQL Database Name  
$DB_TBLName = "tablename"; //MySQL Table Name   
$filename = "Student_export-".time();         //File Name
/*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/    
//create MySQL connection   
$sql = "SELECT * FROM  ".$DB_TBLName ;
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
 or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
//select database   
$Db = @mysql_select_db($DB_DBName, $Connect) 
or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno());   
//execute query
$result = @mysql_query($sql,$Connect) 
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());    
$file_ending = "xls";
//header info for browser
header("Content-Type: application/xls");    
header("Content-Disposition: attachment; filename=$filename.xls");  
header("Pragma: no-cache");
header("Expires: 0");
/*******Start of Formatting for Excel*******/   
//define separator (defines columns in excel & tabs in word)
$sep = "\t"; //tabbed character
//start of printing column names as names of MySQL fields
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");    
//end of printing column names  
//start while loop to get data
    while($row = mysql_fetch_row($result))
    {
        $schema_insert = "";
        for($j=0; $j<mysql_num_fields($result);$j++)
        {
            if(!isset($row[$j]))
                $schema_insert .= "NULL".$sep;
            elseif ($row[$j] != "")
                $schema_insert .= "$row[$j]".$sep;
            else
                $schema_insert .= "".$sep;
        }
        $schema_insert = str_replace($sep."$", "", $schema_insert);
        $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
        $schema_insert .= "\t";
        print(trim($schema_insert));
        print "\n";
    }  
    die;

Thursday, 9 October 2014

Simple Responsive Slider using jquery




Here is a Simple Responsive Slider using jquery which works on every breakpoints. A very simple js/jquery which helps you to modify it according to your requirements.
Download  infinite_Image_Carousel-master

Custom linkedin button for share and auth









  1. <script src="http://platform.linkedin.com/in.js">
  2. api_key:
  3. //onLoad: onLinkedInLoad
  4. scope: r_basicprofile r_emailaddress r_fullprofile
  5. authorize:true
  6. </script>
  7. <script>
  8. function onLinkedInAuth() {
  9. IN.API.Profile("me")
  10. .fields("firstName", "lastName", "industry", "location:(name)", "picture-url", "headline", "summary", "num-connections", "public-profile-url", "distance", "positions", "email-address", "educations", "date-of-birth")
  11. .result(displayProfiles);
  12. IN.UI.Share().params({
  13. url: "http://www.example.com"
  14. }).place()
  15. }

  16. function displayProfiles(profiles) {
  17. console.log(profiles);
  18. member = profiles.values[0];
  19. }

  20. jQuery(document).ready(function(){
  21. jQuery("#linkdinlog").click(function(){
  22. IN.UI.Authorize().place();
  23. IN.Event.on(IN, "auth", onLinkedInAuth);
  24. });
  25. });
  26. </script><a href="javascript:void(0)" id="linkdinlog">link</a>

remove svn files folder using php

some time we forget to export a project on svn and upload that on main server. Result , our main server now have svn file and folders folders. if we want to delete them we have to delete them one by one (if your svn version is old) or we have to upload a new copy of project by exporting project using SVN. It may take a quit long time. So here is the alternate. By using this code you can delete all svn files and folders at once.








  1. $path = $_SERVER['DOCUMENT_ROOT'].'/work/remove-svn-php/'; // path of your directory
  2. header( 'Content-type: text/plain' ); // plain text for easy display

  3. // preconditon: $dir ends with a forward slash (/) and is a valid directory
  4. // postcondition: $dir and all it's sub-directories are recursively
  5. // searched through for .svn directories. If a .svn directory is found,
  6. // it is deleted to remove any security holes.
  7. function removeSVN( $dir ) {
  8. //echo "Searching: $dirnt";

  9. $flag = false; // haven't found svn directory
  10. $svn = $dir . '.svn';

  11. if( is_dir( $svn ) ) {
  12. if( !chmod( $svn, 0777 ) )
  13. echo "File permissions could not be changed (this may or may not be a problem--check the statement below).nt"; // if the permissions were already 777, this is not a problem

  14. delTree( $svn ); // remove the .svn directory with a helper function

  15. if( is_dir( $svn ) ) // deleting failed
  16. echo "Failed to delete $svn due to file permissions.";
  17. else
  18. echo "Successfully deleted $svn from the file system.";

  19. $flag = true; // found directory
  20. }

  21. if( !$flag ) // no .svn directory
  22. echo 'No .svn directory found.';
  23. echo "nn";

  24. $handle = opendir( $dir );
  25. while( false !== ( $file = readdir( $handle ) ) ) {
  26. if( $file == '.' || $file == '..' ) // don't get lost by recursively going through the current or top directory
  27. continue;

  28. if( is_dir( $dir . $file ) )
  29. removeSVN( $dir . $file . '/' ); // apply the SVN removal for sub directories
  30. }
  31. }

  32. // precondition: $dir is a valid directory
  33. // postcondition: $dir and all it's contents are removed
  34. // simple function found at http://www.php.net/manual/en/function.rmdir.php#93836
  35. function delTree( $dir ) {
  36. $files = glob( $dir . '*', GLOB_MARK ); // find all files in the directory

  37. foreach( $files as $file ) {
  38. if( substr( $file, -1 ) == '/')
  39. delTree( $file ); // recursively apply this to sub directories
  40. else
  41. unlink( $file );
  42. }

  43. if ( is_dir( $dir ) ){
  44. //echo $dir;
  45. // die;
  46. rmdir( $dir ); // remove the directory itself (rmdir only removes a directory once it is empty)

  47. }
  48. }

  49. // remove all .svn directories in the
  50. // current directory and sub directories
  51. // (recursively applied)
  52. removeSVN($path);


Tuesday, 31 December 2013

update product quantity on check out page magento


you can do it by editing item.phtml (template/checkout/onepage/review/item.phtml) and these lines after line no #47

    <td class="a-center"><?php echo $_item->getQty() ?></td> 
        <td class="a-center">
            <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" name="update_cart_action" id="cup_<?php echo $_item->getId() ?>"  class="input-text qty" maxlength="12" />
        </td>
       <td> <button type="submit" name="update_cart_action" value="update_qty" title="<?php echo $this->__('shopping-cart-table'); ?>" id="up_<?php echo $_item->getId() ?>" class="button btn-update"><span><span><?php echo $this->__('Update'); ?></span></span></button><td>

and put Jquery code at the end

    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery(".btn-update").click(function(){

            var id = "#c"+this.id;
            var quan = jQuery(id).val();
            var lastChar = id.substr(id.length - 1);

            jQuery.ajax({
                url: "<?php echo Mage::getBaseUrl(); ?>checkout/cart/updatePosts/",
                data: "cart["+lastChar+"][qty]="+quan,
                async: false,
                    success: function(html){

                        location.reload();

                    }
            })
        })
    })
    </script>now override cartcontroller.php and place all the functions of the original cartcontroller.php and rename function updatePostAction by function updatePostsAction.
and change the redirect path to $this->_redirect('checkout/onepage');

Put magento on maintenance mode and it open only on your ip








Today I am going to explain you how to put magento on maintenance mode. That maintenance mode will show to all other user user beside you. So can can work on a live environment if there is any issue.
Some time we all face a problem that something is not working on live environment while it is working on staging. So we have to test it on live environment but it is more difficult to put echo/ die on live site.
you can you do your work by using these steps so only you are able to open site while other see site is under maintenance mode.
Step 1 : put a file on your root with the name “maintenance.flag”
Step 2 : open you index file and find the code
if (file_exists($maintenanceFile) ) {
include_once dirname(__FILE__) . ‘/errors/503.php’;
exit;
}
Now update the code with that code
$ip = $_SERVER['REMOTE_ADDR']; // you can check your ip by http://who.is/
if (file_exists($maintenanceFile) && $ip != “your ip address” ) {
include_once dirname(__FILE__) . ‘/errors/503.php’;
exit;
}

unzip folder and files using php code

<!--?php
$zip = new ZipArchive;
if ($zip->open('test.zip') === TRUE) {
// using $_SERVER['DOCUMENT_ROOT'] if you don't know the where you are
    $zip->extractTo('/my/destination/dir/');
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>