Rss Feed

  1. <?php  
    $img = file_get_contents('http://www.site.com/image.jpg');

    $im = imagecreatefromstring($img);

    $width = imagesx($im);

    $height = imagesy($im);

    $newwidth = '120';

    $newheight = '120';

    $thumb = imagecreatetruecolor($newwidth, $newheight);

    imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    imagejpeg($thumb,'/images/myChosenName.jpg'); //save image as jpg

    imagedestroy($thumb);

    imagedestroy($im);
    ?>

    Refer:
    http://stackoverflow.com/questions/9022610/download-image-from-remote-source-and-resize-then-save

  2. Disable default CakePHP form style

    Friday 26 April 2013

    <?php echo $this->Form->create('Banner', array('action' => 'admin_add','type' => 'file','inputDefaults' => array('label' => false,'div' => false))); ?>

  3. Upload directory:

    $filename = WWW_ROOT . 'uploads' . DS  . $image['name'];

  4. To get file name and  type
    pathinfo

    Example #1 pathinfo() Example
    <?php
    $path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

    echo $path_parts['dirname'], "\n";
    echo $path_parts['basename'], "\n";
    echo $path_parts['extension'], "\n";
    echo $path_parts['filename'], "\n"; // since PHP 5.2.0
    ?>
    The above example will output:
    /www/htdocs/inc
    lib.inc.php
    php
    lib.inc


    getimagesize() — Get the size of an image

  5. MySQL DELETE vs TRUNCATE

    Tuesday 23 April 2013


    Use TRUNCATE TABLE to Start Fresh

    After doing some research I found out that when you truncate a MySQL table, you are actually dropping the database table and re-creating the table from its SQL create statement.  This has one major implication, besides being faster (among other things), it means that all of your autoincrement fields will start over at 1.  I really like that outcome- nice and tidy.

    Use DELETE FROM TABLE to Not Re-Use IDs

    What I usually do (at least in CakePHP) is a deleteAll, which executes a DELETE FROM mysql_table_name which clears out all of the rows in a table.  The major difference- MySQL goes row by row, deleting each row, resulting in a performance hit vs. truncating the same data.  The consequence of only deleting data and not re-creating the table, is that your autoincrement value will remain unchanged.


  6. SEO

    Structure to design website for SEO purpose

    seo silo structure

    Keywords to search
    Eg:

    joomla extenxion   -> will search openly for keyword

    "joomla extension" ->will serach exclusively for keyword

    joomla + extension -> will include extension result in the joomla keyword search result

    joomla - extension -> will exclude extension result in the joomla keyword search result

    allintitle:joomla extension -> will return the result with website with search keyword as title

    inurl:joomla extension -> will return result with url having search keyword

    site:billionbond.com -> will search for all pages in the particular website

    www.google.com/alert -> to get alert of particular keyword in email

    www.google.com/trends -> to get the statistics of the particular keyword




  7. Get checked checkboxes

    Loops through all the checked checkboxes and adds checkbox value to an array using jquery :checkbox selector.


    $(":checkbox:checked").each(
        function() {
            $(this).val();
        }
    );


    Get unchecked checkboxes

    Loops through all the unchecked checkboxes and adds checkbox value to an array.
    $(":checkbox").not(:checked).each(
        function() {
            $(this).val();
        }
    );

    Refer:

  8. Pagination

    Saturday 20 April 2013

    <?php
    // Adam's Custom PHP MySQL Pagination Tutorial and Script
    // You have to put your mysql connection data and alter the SQL queries(both queries)
    // This script is in tutorial form and is accompanied by the following video:
    // http://www.youtube.com/watch?v=K8xYGnEOXYc

    mysql_connect("DB_Host_Here","DB_Username_Here","DB_Password_Here") or die (mysql_error());
    mysql_select_db("DB_Name_Here") or die (mysql_error());
    //////////////  QUERY THE MEMBER DATA INITIALLY LIKE YOU NORMALLY WOULD
    $sql = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC");
    //////////////////////////////////// Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////
    $nr = mysql_num_rows($sql); // Get total of Num rows from the database query
    if (isset($_GET['pn'])) { // Get pn from URL vars if it is present
        $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filter everything but numbers for security(new)
        //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // filter everything but numbers for security(deprecated)
    } else { // If the pn URL variable is not present force it to be value of page number 1
        $pn = 1;
    }
    //This is where we set how many database items to show on each page 
    $itemsPerPage = 10;
    // Get the value of the last page in the pagination result set
    $lastPage = ceil($nr / $itemsPerPage);
    // Be sure URL variable $pn(page number) is no lower than page 1 and no higher than $lastpage
    if ($pn < 1) { // If it is less than 1
        $pn = 1; // force if to be 1
    } else if ($pn > $lastPage) { // if it is greater than $lastpage
        $pn = $lastPage; // force it to be $lastpage's value
    }
    // This creates the numbers to click in between the next and back buttons
    // This section is explained well in the video that accompanies this script

    $centerPages = "";
    $sub1 = $pn - 1;
    $sub2 = $pn - 2;
    $add1 = $pn + 1;
    $add2 = $pn + 2;
    if ($pn == 1) {
        $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    } else if ($pn == $lastPage) {
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
        $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
    } else if ($pn > 2 && $pn < ($lastPage - 1)) {
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
        $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
    } else if ($pn > 1 && $pn < $lastPage) {
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
        $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
        $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
    }
    // This line sets the "LIMIT" range... the 2 values we place to choose a range of rows from database in our query
    $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
    // Now we are going to run the same query as above but this time add $limit onto the end of the SQL syntax
    // $sql2 is what we will use to fuel our while loop statement below
    $sql2 = mysql_query("SELECT id, firstname, country FROM myTable ORDER BY id ASC $limit");
    //////////////////////////////// END Adam's Pagination Logic ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////// Adam's Pagination Display Setup /////////////////////////////////////////////////////////////////////

    $paginationDisplay = ""; // Initialize the pagination output variable
    // This code runs only if the last page variable is ot equal to 1, if it is only 1 page we require no paginated links to display
    if ($lastPage != "1"){
        // This shows the user what page they are on, and the total number of pages
        $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of ' . $lastPage. '
    &nbsp;  &nbsp; &nbsp; ';
        // If we are not on page 1 we can place the Back button
        if ($pn != 1) {
            $previous = $pn - 1;
            $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Back</a> ';
        }
        // Lay in the clickable numbers display here between the Back and Next links
        $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
        // If we are not on the very last page we can place the Next button
        if ($pn != $lastPage) {
            $nextPage = $pn + 1;
            $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Next</a> ';
        }
    }
    ///////////////////////////////////// END Adam's Pagination Display Setup ///////////////////////////////////////////////////////////////////////////
    // Build the Output Section Here

    $outputList = '';
    while($row = mysql_fetch_array($sql2)){

        $id = $row["id"];
        $firstname = $row["firstname"];
        $country = $row["country"];

        $outputList .= '<h1>' . $firstname . '</h1><h2>' . $country . ' </h2><hr />';
       
    // close while loop

    ?>
    <html>
    <head>
    <title>Adam's Pagination</title>

    <style type="text/css">
    <!--

    .pagNumActive {
        color: #000;
        border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
    }
    .paginationNumbers a:link {
        color: #000;
        text-decoration: none;
        border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
    }
    .paginationNumbers a:visited {
        color: #000;
        text-decoration: none;
        border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
    }
    .paginationNumbers a:hover {
        color: #000;
        text-decoration: none;
        border:#060 1px solid; background-color: #D2FFD2; padding-left:3px; padding-right:3px;
    }
    .paginationNumbers a:active {
        color: #000;
        text-decoration: none;
        border:#999 1px solid; background-color:#F0F0F0; padding-left:3px; padding-right:3px;
    }
    -->
    </style>

    </head>
    <body>
       <div style="margin-left:64px; margin-right:64px;">
         <h2>Total Items: <?php echo $nr; ?></h2>
       </div>
          <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
          <div style="margin-left:64px; margin-right:64px;"><?php print "$outputList"; ?></div>
          <div style="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFF; border:#999 1px solid;"><?php echo $paginationDisplay; ?></div>
    </body>
    </html>

  9. Ecommerce CMS Websites

    Thursday 11 April 2013


    It depends on what you mean by "large" :) Have a look at who's using some of the most popular PHP e-commerce frameworks:
    - Magento: http://www.magentocommerce.com/product/enterprise-whos-using-magento
    - OpenCart: http://www.opencart.com/index.php?route=feature/liveshop
    - PrestaShop: http://www.prestashop.com/en/showcase
    - osCommerce: http://shops.oscommerce.com/

  10. Jquery noConflict

    Wednesday 10 April 2013



    Actual code
    $(document).ready(function(){
     
     $('li.mainlevel').mousemove(function(){
     $(this).find('ul').slideDown();//you can give it a speed
      });
     $('li.mainlevel').mouseleave(function(){
     $(this).find('ul').slideUp("fast");
      });
     
    });



    To avoid no conflictvar j = jQuery.noConflict();   // define and replace object $ with j
    j(document).ready(function(){
     
      j('li.mainlevel').mousemove(function(){
      j(this).find('ul').slideDown();//you can give it a speed
      });
      j('li.mainlevel').mouseleave(function(){
      j(this).find('ul').slideUp("fast");
      });
     
    });

  11. MySQL to know

    Tuesday 9 April 2013

    MySQL storage engines 

    MySQL provides various storage engines for its tables as below:

    MyISAMInnoDBMERGEMEMORY (HEAP)ARCHIVECSVFEDERATED

    Manage database 

    To create database

    CREATE DATABASE [IF NOT EXISTS] database_name;

    To show all database
    SHOW DATABASES;

    Use Database
    USE database_name;

    Removing Databases
    DROP DATABASE [IF EXISTS] database_name;


  12. Javascript to know

    Sunday 7 April 2013


    How can we submit from without a submit button?
     
    We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit(); function to submit the form.

  13. Enable CK editor in CakePHP

    Thursday 4 April 2013

    How to install and integrate CKEditor to CakePHP?  
    1. Download CKEditor from www.ckeditor.com
    2. Copy files from the zipped folder to "webroot/js/ckeditor/"
    3. In the view where you want to display the editor, put the following script on the top of the page (or somewhere before textarea which you want to contain editor):
      <?php echo $this->Html->script('ckeditor/ckeditor');?>
      This scipt will include the "webroot/js/ckeditor.js" file to your view.
    4. Create the textarea and give it a class named "ckeditor"
      <?php echo $this->Form->textarea('content',array('class'=>'ckeditor'))?>
     The editor is now displaying instead of raw textarea.

  14. MySQL to know

    Wednesday 3 April 2013


    How to truncate only if table exists?
    DROP TABLE IF EXISTS `name`
    CREATE TABLE IF NOT EXISTS `name`