20. Session

What is a PHP Session?
The web server does not know who you are or what you do, because the HTTP address doesn’t maintain state. Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser.

So; Session variables hold information about one single user, and are available to all pages in one application.

Start a PHP Session
A session is started with the session_start() function.

Session variables are set with the PHP global variable: $_SESSION.

Example:

<?php
	session_start();
	$_SESSION['name']="Username";

	echo isset($_SESSION['name'])?$_SESSION['name']." is available":"The user not Exist";
	
?>

Destroy a PHP Session
To remove all global session variables and destroy the session, use session_unset() and session_destroy():

Example

<?php
	session_start();
	$_SESSION['name1']="Unsername";
	session_unset();
	session_destroy();
	echo isset($_SESSION['name1'])?$_SESSION['name1']." is available":"The user not Exist";
	
?>

3. Readmore Menu Content and Readmore Category Article

1.crud.php

<?php

class Crud {

    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die("connection error");
        }
    }

    /* This is for readmore menu content */
    public function readMenuContent($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE menu_id=$id AND status= 1");
        if (mysqli_num_rows($query) > 0) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }
    
    /* This is for readmore Article */
    public function readArticle($table, $id) {
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE art_id=$id AND status = 1");
        if (mysqli_num_rows($query)) {
            return mysqli_fetch_assoc($query);
        } else {
            return false;
        }
    }

}

$obj = new Crud();

2.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">

        <?php
        /* This is for menu content */
        if (isset($_REQUEST['menu_id'])) {
            $content = $obj->MenuContent("menus", $_REQUEST['menu_id']);
            //echo $content["menu_content"];

            /* Start from this here for Readmore content */
            extract($content);
            $convert_array = explode(' ', $menu_content);
            //print_r($convert_array);
            if (count($convert_array) <= 210) {
                echo "<p>$menu_content</p>";
            } else {
                $slice = array_slice($convert_array, 0, 209);
                echo "<p>" . implode(' ', $slice) . "<a style=text-decoration:none;color:red; href=index.php?id=$menu_id>&nbsp;&nbsp;Read More</a> </p>";
            }
        } elseif (isset($_REQUEST['id'])) {
            $readmore = $obj->readMenuContent("menus", $_REQUEST['id']);
            //print_r($readmore);
            echo $readmore['menu_content'];
        } /* finish line Readmore content */



        /* This is for category articles */
        if (isset($_REQUEST['cat_id']) ? $_GET['cat_id'] : null) {
            $articles = $obj->CatArticle("articles", $_REQUEST['cat_id']);
            //echo "<pre>";
            //print_r($articles);
            foreach ($articles as $article) {
                extract($article);
                echo "<h2>" . $article["art_title"] . "</h2>";
                //echo "<p>" . $article["art_content"] . "</p>";

                /* Start from this here for Readmore Article */
                $art_convert_array = explode(' ', $art_content);
                //print_r($art_convert_array);
                if (count($art_convert_array) <= 160) {
                    echo "<p>" . $art_convert_array["art_content"] . "</p>";
                    //echo "<p>$art_content</p>";
                } else {
                    $art_slice = array_slice($art_convert_array, 0, 159);
                    echo "<p>" . implode(' ', $art_slice) . "<a style=text-decoration:none;color:red; href=index.php?art_id=$art_id>&nbsp;&nbsp;Read More</a> </p>";
                }
            }
        } elseif (isset($_REQUEST['art_id'])) {
            $artReadmore = $obj->readArticle("articles", $_REQUEST['art_id']);
            echo "<h2>" . $artReadmore['art_title'] . "</h2>";
            echo "<p>" . $artReadmore['art_content'] . "</p>";
        } /* finish line Readmore Article */
        ?>

        <br/>
    </div>

Output:
readmore

2. Dynamic Category and Category Articles show

1.Create Database Table articles

article

2.Crud.php file

<?php

class Crud {

    public $conn;

    public function __construct() {
        $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die ("connection error");
            
        }
    }
   
    /* This is for category show */
    public function categories($table){
        $query = mysqli_query($this->conn, " SELECT * FROM $table");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query, MYSQL_ASSOC);
        } else{
            return false;
        }
    }
    
    /* This is for Category Article show*/
    public function CatArticle($table,$id){
        $query = mysqli_query($this->conn, "SELECT * FROM $table WHERE cat_id=$id");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query,MYSQL_ASSOC);
        } else{
            return false;
        }
    }

}

$obj = new Crud();

3.sidebar.php

<div class="content1_box2 flt_lt">
    <h2>Latest work</h2>
    <div class="content1_box2_img"><a href="#"><img src="images/img.jpg" width="300" height="135" alt="img" /></a></div>
    <p>Pellentesque diam ligula, egestas eget rhoncus vel, hendrerit in sem. Viva mus laoreet erat sit amet ante ullamcorper vestibulum. <a href="#">Read More</a></p>
    <h2>Categories</h2>
    <ul>
        <?php
        $categories = $obj->categories("categories");
        foreach ($categories as $category) {
            extract($category);
            ?> <li><a href="index.php?cat_id=<?php echo $cat_id; ?>"><?php echo $cat_name; ?></a></li>
            <?php
        }
        ?>
    </ul>
    <div class="clear"></div>
</div>

4.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">

        <?php
        /* This is for category articles */
        if (isset($_REQUEST['cat_id'])) {
            $articles = $obj->CatArticle("articles", $_REQUEST['cat_id']);
            //echo "<pre>";
            //print_r($articles);
            foreach ($articles as $article) {
                echo "<h2>" . $article["art_title"] . "</h2>";
                echo "<p>" . $article["art_content"] . "</p>";
            }
        }
        ?>

        <br/>
    </div>

Output like following screenshot
category

1. Dynamic menu and menu content show

1.At first you have to do separate the whole template.section header, content, banner, sidebar, footer.
2.Look like following index.php file

<?php
include_once('header.php');
include_once('banner.php');
include_once('content.php');
include_once('sidebar.php');
include_once('footer.php');
?>

3.create database table

db-looking

4.create crud.php

<?php class Crud { public $conn; public function __construct() { $this->conn = mysqli_connect("localhost", "root", "", "fresh");
        if (mysqli_connect()) {
            //echo "Connect Successfully";
        } else {
            die ("connection error");
            
        }
    }
    /* This is for menu showing */
    public function Menu($table){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE STATUS=1");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_all($query,MYSQLI_ASSOC);
        } else {
            echo "Menu not showing";
        }
        
    }
    
    /* This is for menu content */
    public function MenuContent($table,$id){
        $query = mysqli_query($this->conn, "SELECT * FROM  $table WHERE menu_id=$id");
        if(mysqli_num_rows($query)>0){
            return mysqli_fetch_assoc($query);
        } else{
            return false;
        }
    }

}

$obj = new Crud();

5.header.php

<?php
include_once('crud.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Demo site</title>
        <!-- SET: FAVICON -->
        <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
        <!-- END: FAVICON -->
        <!-- SET: STYLESHEET -->
        <link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
        <!-- END: STYLESHEET -->
    </head>
    <body>
        <!-- wrapper starts -->
        <div class="wrapper">
            <!-- main Starts -->
            <div class="main">
                <!-- Header Starts -->
                <div class="header">
                    <div class="logo flt_lt">
                        <h1><a href="#">Logo</a></h1>
                        <p>Your slogan goes here</p>
                    </div>
                    <div class="header_right flt_rt">
                        <ul>
                            <li><a href="#"><img src="images/twitter-logo.png" width="16" height="16" alt="twitter" class="img" /><span>twitter</span></a></li>
                            <li><a href="#"><img src="images/fb-logo.png" width="16" height="16" alt="facebook" class="img"  /><span>facebook</span></a></li>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                    <div id="nav">
                        <ul>
                            <li><a href="index.php">HOME </a></li>
                            <?php
                            $headmenus = $obj->Menu("menus");
                            foreach ($headmenus as $singlemenu) {
                                extract($singlemenu);
                                //print_r($singlemenu);
                                ?>
                                <li><a href="index.php?menu_id=<?php echo $menu_id;?>"><?php echo $menu_name; ?></a></li>
                                <?php
                            }
                            ?>
                        </ul>
                        <div class="clear"></div>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="clear"></div>
                <!-- Header ends -->
                <!-- content Starts -->
                <div class="content">

6.content.php

<div class="content1">
    <div class="content1_box1 flt_lt">
        <!-- This code is for Menu content showing -->
        <?php
           if(isset($_REQUEST['menu_id'])){
               $menucontent = $obj->MenuContent("menus", $_REQUEST['menu_id']);
               //print_r($menucontent);
               echo $menucontent['menu_content'];
           }
        ?>
        
        <br/>
    </div>

Final showing like following screenshot
template-menu

PHP extension is missing


|| New version magento 2 PHP Extension intl is missing   
1. Go to the file php.ini 
2. Search for ;extension=php_intl.dll
3. Remove semicolon and restart server. It will work.


|| Magento 1.4v-1.9.1 version 
1. Go to the file php.ini 
2. Search for ;extension=php_curl.dll
3. Remove semicolon and restart server. It will work.

Magento Code

http://magento-code-snippets.tumblr.com/

||  placing upsells in the product view page
    
     <block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml">
          <action method="setColumnCount"><columns>5</columns></action>
          <action method="setItemLimit"><type>upsell</type><limit>5</limit></action>
     </block>
     
     view page: <?php echo $this->getChildHtml('upsell_products'); ?>
     

||  page-title category-title
    catalog > category > view.phtml

||  get product price
    <div class="product_price">  
         <?php $_productCollection=$this->getLoadedProductCollection();
         $productBlock = $this->getLayout()->createBlock('catalog/product_price');
         echo $productBlock->getPriceHtml($_product); ?>
    </div>

||  Configuring numbres of products displayed on the mini cart:
    System > Configuration > under Sales > Checkout > Shopping Cart Sidebar

||  How to enable/disable the demo store notice in Magento.
    System tab > Configuration > Design >  HTML Head > Display Demo Store Notice.
    notice text: page > html > notice.phtml


||  Proceed to Checkout
    app/design/frontend/default/default/template/checkout/onepage/link.phtml


||  Header Top links 
    template/page/template/links.phtml

||  To understand new order id:
    go > db Look in "eav_entity_store" and find increment_last_id.
    Change "increment prefix" to a name that could understood for new order id.
    


||  sales order view All Status in Admin Panel for Comments History:
    go to design/adminhtml/def/def/template/sales/oreder/view/history.phtml

    Replace :	
    <?php foreach ($this->getStatuses() as $_code=>$_label): ?>
    To :
    <?php foreach (Mage::getSingleton('sales/order_config')->getStatuses() as $_code=>$_label): ?>


||  remove white image frame:
    <li><a href="<?php echo $this->getProductUrl()?>" title="<?php echo $this->escapeHtml($this->getProductName()) ?>" class="product-image"><img src="<?php echo $this->getProductThumbnail()->keepFrame(false)->resize(45, 50)->setWatermarkSize('30x10'); ?>" width="45" height="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" /></a></li>

||  wishlist product image size location:
    E:\xampp\htdocs\bbrands\app\design\frontend\bbrands\default\template\wishlist\sidebar.phtml

||  cart page product image size location:
    E:\xampp\htdocs\bbrands\app\design\frontend\bbrands\default\template\checkout\cart\item\default.phtml

||  Mini cart product image size location:
    E:\xampp\htdocs\bbrands\app\design\frontend\bbrands\default\template\checkout\cart\sidebar\default.phtml

||  where is product category  title
    app\design\frontend\default\default\template\catalog\category\view.phtml

||  How to product count:

<!-- total product count -->
    <?php $_helper = $this->helper('catalog/output'); ?>
    <?php $_category_detail = Mage::registry('current_category'); ?>
    <?php $_category_detail->getName(); ?>
    <?php $_category_detail->getId(); ?>
    <p>
        <?php
        $products_count = Mage::getModel('catalog/category')->load($_category_detail->getId())->getProductCount();
        echo'(' . ($products_count) . '&nbsp;' . 'Products Founds)';
        ?>
    </p><!-- count end -->

||	how to set up mobile theme
	iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini

||	<?php echo $this->getChildHtml('topMenu') ?>
	<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
	
||   Product total view
	<div class="total_view">
		<?php 

			$id = $id=$_helper->productAttribute($_product, $_product->getId(), 'id');

			$fromDate = '2013-12-10';
			$toDate   = now();
			$viewedProducts = Mage::getResourceModel('reports/product_collection')->addViewsCount($fromDate, $toDate);
			foreach($viewedProducts as $product) {
			if($product->getData('entity_id')==$id)
			{
				echo  "Total View Count: " . $product->getData('views');
			}
		}
		?>
	</div>

||	Checkout page Button Place Order click then ajax loading title Submitting order information 
	app/design/frontend/mypackage/mytheme/template/checkout/onepage/review/info.phtml

||	Edit was added to your shopping cart in magento 
	app/code/core/Mage/Checkout/controllers/CartController.php
	search this :  was added to your shopping cart.

||	Discount Codes
	app/design/frontend/base/default/template/checkout/cart/coupon.phtml


||	Product column count in xml page
	<action method="setColumnCount"><count>3</count></action>


||	How to Remove "Starting at" Price in Magento
	atalog/product/price.phtml
	<span class="price-label"><?php echo $this->__('Starting at:') ?></span>

||	product view page compare & wishlist
	catalog>product>view>addto.phtml

||	product view page add to cart
	catalog>product>view>addtocart.phtml

||	Magento Currency Drop Down only Currency Symbols like BDT, USD >  template/directory/currency.phtml 
    <?php //echo $_name ?> <?php echo $_code ?>

||	Currency symbols from System->Manage Currency->Symbols.

||  Magento Currency Symbol 404's when i go to admin
    solve: Change line 68 in app\code\core\Mage\CurrencySymbol\etc\config.xml
        
    <currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
                             To
    <currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>
         

||	Currency:
	1.catalog.xml or page.xml
	   <block type="directory/currency" name="currency" as="currency" template="directory/currency.phtml"/>
        or
	2.anywhere phtml file
	   <?php echo $this->getLayout()->createBlock('directory/currency')->setTemplate('directory/currency.phtml')->toHtml(); ?>

||  Currency remove: local.xml file
    <catalog_category_default><remove name="currency" /></catalog_category_default>
	
	

||	clear shopping cart & Update Shopping Cart is not working 
	---> In your /app/design/frontend/yourthemepackage/default/template/checkout/cart.phtml file or /app/design/frontend/default/yourtheme/template/checkout/cart.phtml file
		 Just place on line 50 just after getUrl('checkout/cart/updatePost') ?>" method="post"> paste the below code
		 <?php echo $this->getBlockHtml('formkey'); ?>


||	Login frontend edit
	app/design/frontend/base/template/persistent/customer/form/login.php

		 
||	Checkout Login edit frontend (CHECKOUT AS A GUEST OR REGISTER)
	app/design/frontend/base/template/persistent/checkout/onepage/login.phtml


||	Product url:
	<?php echo $_product->getProductUrl() ?>

||	name :
	<?php echo $this->__('Go') ?>

||	Default product image
	1. System > Configuration > Catalog > Product Image Placeholders
	2. skin\frontend\default\mytheme\images\catalog\product\placeholder

||	Adding Links to your topLinks
	app/design/frontend/<yourtheme>/default/template/page/template/links.phtml

||	page > html >breadcrumbs.phtml

||	Only Contact Us page breadcrumbs:layout>contacts.xml
	<reference name="root">
	  <action method="unsetChild"><alias>breadcrumbs</alias></action>
		<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs">
			<action method="addCrumb">
			  <crumbName>home</crumbName>
			  <crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
			</action> 
			<action method="addCrumb">
			  <crumbName>contacts</crumbName>
			  <crumbInfo><label>Contact us</label><title>Contact us</title></crumbInfo>
			</action>
	  </block>
	  <action method="setTemplate"><template>page/empty.phtml</template></action>
	  <action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
	</reference>

	
||	Breadcrumbs>page.xml:
	<label>Breadcrumbs</label> 
	<label>Main Content Area</label>


||	Breadcrumbs Adding to cms pages in Magento:
	<?php
	if ((!$crumbs || !is_array($crumbs)) && $this->getUrl('')!= $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))) {
		$breadcrumb = $this->getLayout()->getBlock('breadcrumbs');
		$breadcrumb->addCrumb('home', array('label' => Mage::helper('cms')->__('Home'), 'title' => Mage::helper('cms')->__('Home Page'), 'link' => Mage::getBaseUrl()));
		$breadcrumb->addCrumb('my_account activeBreadcrumb', array('label' => $this->getLayout()->getBlock('head')->getTitle(), 'title' => $this->getLayout()->getBlock('head')->getTitle(), 'last' => 1));
		$crumbs = $breadcrumb->_crumbs;
	 
	}
	?>

||	Showing Breadcrums anywhere in Magento:
	<?php echo $this->getLayout()->getBlock('breadcrumbs')->toHtml()?>
	

||	if you want to condition that the slide show only home page:
        
        // If it is the home page, then just show up on the home page, other pages don't show 
	||  <?php if( Mage::getSingleton('cms/page')->getIdentifier()=='home') :?>
        <div class=""></div>    
		<?php endif;?>
	or
	   // if it is the home page, then don't show up on the home page, other pages show up 
	||	<?php if(!(Mage::getSingleton('cms/page')->getIdentifier() == 'home'  && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms')) : ?>
	

||	Short Description
	<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>

||	Product Detail page Description
	<?php
		$my_product = Mage::getModel('catalog/product')->load($_product->getId());
		echo $my_product->getDescription();
	?>

||	How to get attribute name and value?
	<p class="attribute"><?php echo "Author:".$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('author');?></p>

||	One Page Checkout Success 2column
	---> app\design\frontend\default\default\layout\checkout.xml
		 <label>One Page Checkout Success</label>

||	Product Url
	<a href="<?php echo $_product->getProductUrl() ?>">Product Details</a>

||	Forgot Your Password? column layout->
	customer.xml

||	Admin Change(xampp\htdocs\onlinesales\app\design\adminhtml\default\default\template)-
	1. login.phtml file:69 line
	2. forgotpassword.phtml file: 64 line
	<p class="legal"><?php echo Mage::helper('adminhtml')->__('Copyright &copy; FSB.', date('Y')) ?></p>

||	Search Bar Anywhere
	<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalogsearch/form.mini.phtml')->toHtml();?>	

||	Advanced Search
	<a href="<?php echo $this->getUrl('catalogsearch/advanced/')?>"><?php echo $this->__('Advanced Search');?></a>

||	call name<li><a href="<?php echo $this->getUrl('');?>"><?php echo $this->__('Home');?></a></li>

||	media img src for phtml
	<img alt="author" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);?>/wysiwyg/author/Humayun-ahmed.jpg">

||	media img src for block:
	<a href="{{store url=''}}"><img src="{{media url='folder/sub1.jpg'}}" alt="" /></a>

||	page.xml:
	<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">


||	how to call topmenu.phtml in 2columns-left.phtml page
	<?php echo $this->getLayout()->createBlock('page/html_topmenu')->setTemplate('page/html/topmenu.phtml')->toHtml();?>

||	Diaplay SKU On The Product view Page:
	<p class="p_code">Product Code: <?php echo nl2br($_product->getSku()) ?></p>
	<?php echo $this->htmlEscape($_product->getSku()) ?>
	<?php echo $sku = Mage::getModel('catalog/product')->load($_product->getId())->getSku();?>


<-- Product Name call --->
<?php echo Mage::getModel('catalog/category')->load(20)->getName(); ?>

<-- Name & view more link-->
<?php $cate_id = 15; ?>
<h2><?php echo Mage::getModel('catalog/category')->load($cate_id)->getName(); ?> <a href="<?php echo Mage::getModel('catalog/category')->load($cate_id)->getUrl(); ?>"><?php echo $this->__('View More')?></a></h2>

||	product in phtml-page:
	<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(3)->setTemplate('catalog/product/list.phtml')->toHtml();?>

||	product in home page from Block
	{{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}
		or
	{{block type="catalog/product_list" column_count="4" category_id="45" limit="16" template="catalog/product/custom_scroll.phtml"}}

||	<?php $_columnCount = 4 //$this->getColumnCount(); ?>	

||	block call
	<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('opcontent')->toHtml() ?> 

||	cms page link:
	<div class="home_page">{{block type="core/template"template="page/home.phtml"}}</div>

||	catalog.xml>
	<!--Category default layout-->
	<!--Category layered navigation layout-->
	<action method="setColumnCount"><count>4</count></action>

||	no conflict jequry:
	$j = jQuery.noConflict();

||	Home page>phtml page link:
	<div class="custom_menu">
		<link rel="stylesheet" type="text/css" href="<?php echo $this->getSkinUrl('navigation/css/nav.css');?>" media="all" />
		<?php echo $this->getLayout()->createBlock('navigation/navigation')->setTemplate('navigation/left.phtml')->toHtml() ?>
	</div>

||	compare:
	<?php echo $this->getLayout()->createBlock('catalog/product_compare_sidebar')->setTemplate('catalog/product/compare/sidebar.phtml')->toHtml();?>

||	show mycart in home page from block:
	{{block type="checkout/cart_sidebar" template="checkout/cart/sidebar.phtml"}}

||	mycart xml page
	<block type="checkout/cart_sidebar" name="checkout/cart_sidebar" template="checkout/cart/sidebar.phtml"/>		
	
||	Mycart:
	<?php echo $this->getLayout()->createBlock('checkout/cart_sidebar')->setTemplate('checkout/cart/sidebar.phtml')->toHtml();?>

||	Newsletter in phtml:
	<?php echo $this->getLayout()->createBlock('newsletter/subscribe')->setTemplate('newsletter/subscribe.phtml')->toHtml();?>
	or
	<?php echo $this->getChildHtml('newsletter') ?>

||	show newsletter from block:
	{{block type="newsletter/subscribe" template="newsletter/subscribe.phtml"}}

||	Wishlist:
	<?php echo $this->getLayout()->createBlock('wishlist/customer_wishlist')->setTemplate('wishlist/sidebar.phtml')->toHtml();?>

||	Wishlist href link:
	<?php echo $this->helper('wishlist')->getListUrl()?> 

||	gaterthen code &gt; 

||	copyright code &copy;

||	Cart Count:
	<span class="my_bag"><a href="<?php echo Mage::helper('checkout/cart')->getCartUrl(); ?>">My Bag <?php $testc=Mage::helper('checkout/cart')->getItemsCount(); if($testc==0){echo "Empty";} else{ echo $testc;}?></a></span>
	<?php echo Mage::helper('checkout/cart')->getItemsCount();?>

||	Cart total amount 	
	<?php
		$grandTotal = Mage::helper('checkout/cart')->getQuote()->getGrandTotal();
		$text = $this->__('%s', Mage::helper('core')->formatPrice($grandTotal, false));
	?>
	<span class="head_amount"><?php echo $text; ?></span>
	
	
||	Can I use multiple versions of jQuery on the same page?
	Ans:http://stackoverflow.com/questions/1566595/can-i-use-multiple-versions-of-jquery-on-the-same-page
	<!-- load jQuery 1.1.3 -->
	<script type="text/javascript" src="http://example.com/jquery-1.1.3.js"></script>
	<script type="text/javascript">
	   var jQuery_1_1_3 = $.noConflict(true);
	</script>

	<!-- load jQuery 1.3.2 -->
	<script type="text/javascript" src="http://example.com/jquery-1.3.2.js"></script>
	<script type="text/javascript">
	   var jQuery_1_3_2 = $.noConflict(true);
	</script>


||	mage media link magento:
	<?php
	$media 	 = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
	$regFile = $media.'reg/regi.pdf';
	?><a href="<?php echo $regFile;?>">Download</a>

||	How to add related products tab in products detail page
		1.Go layout\catalog.xml
		search this> <block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
		2.<action method="addTab" translate="title" module="catalog"><alias>related</alias><title>Related Product</title><block>catalog/product_list_related</block><template>catalog/product/view/related.phtml</template></action>
		3.catalog\product\view>related.phtml page create and in this page <?php echo $this->getLayout()->getBlock('catalog.product.related')->toHtml()?> paste
		4.Related product image size (catalog\product\list\ralated.phtml)
		5.If you don't see output, you have to do must be cash refresh and logout

||	Display Related products in product details page:
	<?php //echo $this->getChildHtml('related'); ?>
	<?php //echo $this->getChildHtml('catalog.product.related') ?>
	<?php echo $this->getLayout()->getBlock('catalog.product.related')->toHtml()?>

	
||	Login & Logout:
	<ul>
		<?php if (Mage::getSingleton('customer/session')->isLoggedIn()==1): ?>
		<li class="first"><a title="Log Out" href="<?php echo $this->getUrl('customer/account/logout') ?>">Log Out</a></li>
		<?php else:?>
		<li class="first"><a title="Log In" href="<?php echo $this->getUrl('customer/account/login') ?>">Log In</a></li> | 
		<li class=""><a title="Register" href="<?php echo $this->getUrl('customer/account/create') ?>">Register</a></li> |
		<?php endif;?>
		<li><p>or create an<a href="<?php echo $this->getUrl('customer/account');?>">Account</a></p></li>
	</ul>

||	product onmouseover:
	<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(true)->resize(192,224); ?>" width="192" height="224" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(true)->resize(192,224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(true)->resize(192,224) ?>';" /></a>

||	Audio song added code:
	<div style="position:fixed; top:0; right:0; " class="auido_play">
		<audio loop="true" autoplay="autoplay" controls="controls">
			<source type="audio/wav" src="<?php echo $this->getSkinUrl('css/song.mp3');?>"></source>
		</audio> 
	</div>
	<embed src="<?php //echo $this->getSkinUrl('css/song.mp3');?>" autostart="true" loop="true"width="2" height="0"></embed> 
	<a href="<?php //echo $this->getSkinUrl('css/song.mp3');?>">Play music</a>


||	Online Visitor and Total Visitors in Magento:
	<?php
	$visitor_count = Mage::getModel('log/visitor_online')->prepare()->getCollection()->count();
	if(!empty($visitor_count) && $visitor_count > 0)
	{
		$cnt =  $visitor_count;
		echo 'Visitors online :'.$cnt;
	}
	$write = Mage::getSingleton('core/resource')->getConnection('core_write');
	$readresult=$write->query("SELECT * FROM log_visitor ORDER BY visitor_id DESC LIMIT 1 ");
	while ($row = $readresult->fetch() )
	{
		echo "Total Visitors".$row['visitor_id'];
	}
	?> 

||	Online Visitor from BBrands:
	<?php
		 $visitor_count = Mage::getModel('log/visitor_online')->prepare()->getCollection()->count();
		 if(!empty($visitor_count) && $visitor_count > 0)
		 {
			echo $visitor_count.' Online Visitors'; 
		 }
	?>

Dynamic Menu

<!-----This is for All menu----->
<?php 
$rootcatId= Mage::app()->getStore()->getRootCategoryId(); 
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
function  get_categories($categories) {
    $array= '<ul>';
    foreach($categories as $category) {
        $cat = Mage::getModel('catalog/category')->load($category->getId());
        $count = $cat->getProductCount();
        $array .= '<li>'.
        '<a href="' . Mage::getUrl($cat->getUrlPath()). '">' . 
                  $category->getName() . "(".$count.")</a>\n";
        if($category->hasChildren()) {
            $children = Mage::getModel('catalog/category')->getCategories($category->getId());
             $array .=  get_categories($children);
            }
         $array .= '</li>';
    }
    return  $array . '</ul>';
}
echo  get_categories($categories); 
echo "<div class=\"clearer\"></div>";
?>
<!------End------->

<!------Only Current Menu > submenu-------->
<div class="left_menu">
	<?php
		$routeDetect = Mage::app()->getFrontController()->getRequest()->getRouteName();
		if($routeDetect == 'catalog') :
	?>
	<div class="block block-whishlist">
		<div class="block-title">
			<strong><span>Current Categories</span></strong>
		</div>
		<div class="block-content">
			<?php	
				$_current_category =Mage::registry('current_category')->getId();
				$collection = Mage::getModel('catalog/category')->getCategories($_current_category);
				$helper     = Mage::helper('catalog/category');	
			?>
			<ul>
				<?php foreach ($collection as $cat):?>
					<?php if($cat->getIsActive()):?>
						<li style="border-bottom: 1px solid #ddd">
							<a href="<?php echo $helper->getCategoryUrl($cat);?>">             
								<cite><?php echo $cat->getName();?></cite>
							</a>
							<?php
								$collection_sub = Mage::getModel('catalog/category')->getCategories($cat->getId());									
							?>
							<ul>
								<?php foreach ($collection_sub as $sub):?>
									<?php if($sub->getIsActive()):?>
										<li border-bottom: 1px solid #ddd>
											<a href="<?php echo $helper->getCategoryUrl($sub);?>">             
											&nbsp;<cite><?php echo $sub->getName();?></cite>
											</a>
										</li>	
									<?php endif;?>
								<?php endforeach;?>	
							</ul>		
						</li>
					<?php endif;?>
				<?php endforeach;?>
			</ul>	
		</div>
	</div>
	<?php endif;?>							
	<?php
		$routeDetect = Mage::app()->getFrontController()->getRequest()->getRouteName();
		if($routeDetect != 'customer') :
	?>
	<?php endif;?>
</div>
<!---------End--------->

6. Data Delete

1.Method
obviously have to put this code in fresh.php. where have your database connect.

/* Data Delete */
    
    public function Delete($table,$id){
        $query = mysqli_query($this->connect,"DELETE FROM $table WHERE id=$id");
        if(mysqli_affected_rows($this->connect)>0){
            return true;
        } else{
            return false;
        }
    }

2.tabulize_data.php

<?php
include("fresh.php");
if (isset($_REQUEST['id'])) {
    /* The isset () used to check whether a variable is set or not.
       If a variable is already unset.The isset() return false.
     */
    //super global variable $_REQUEST uses to collect the value of the input field:
    if ($obj->Delete("members", $_REQUEST['id'])) {
        $err_msg = "Successfully Deleted";
    } else {
        $err_msg = "No Data Delete";
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Show Database</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    </head>

    <body>
        <div style="width: 800px; margin: 0 auto">
            <?php
            echo (isset($err_msg)) ? $err_msg : "";
            ?>
            <table class="table table-bordered table-hover" style="text-align: center;">
                <tr>
                    <td>Id</td>
                    <td>Name</td>
                    <td>E-mail</td>
                    <td>Phone</td>
                    <td>Address</td>
                    <td>Action</td>
                </tr>
                <?php
                $team = $obj->getData("members");
                //print_r($team);
                foreach ($team as $single) {
                    extract($single);
                    ?>   
                    <tr>
                        <td><?php echo $id; ?></td>
                        <td><?php echo $name; ?></td>
                        <td><?php echo $email; ?></td>
                        <td><?php echo $phone; ?></td>
                        <td><?php echo $address; ?></td>
                        <td><a href="edit.php?id=<?php echo $id; ?>" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></a>&nbsp;<a href="tabulize_data.php?id=<?php echo $id; ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></a></td>
                    </tr>
                    <?php
                }
                ?>
                <td colspan="6" align="right"><a class="btn btn-info" href="insert.php">Add New Member</a></td>
            </table>
        </div>
    </body>
</html>

Output following screenshot:
Delete