Saturday, November 17, 2012

select all data between two dates using mysql

SELECT *
FROM `product`
WHERE (createdate BETWEEN '2012-11-19 14:15:55' AND '2012-11-29 21:58:43');

Hope enjoy:)

htaccess allow access php specific file

<Files ~ "^piwik\.(js|php)|robots\.txt$">
    Allow from all
    Satisfy any
</Files>

how to post data to other page using javascript and php

<script  language="javascript">
function postdatasend(data){
var pnamevalue=document.getElementById('prname'+data).value;
var ppricevalue=document.getElementById('prprice'+data).value;
var mapForm = document.createElement("form");
    mapForm.target = "Map";
    mapForm.method = "POST"; // or "post" if appropriate
    mapForm.action = "showsingleproduct.php";
    mapForm.target='_self';
var pname = document.createElement("input");
    pname.type = "hidden";
    pname.name = "proname";
    pname.value = pnamevalue;   
    mapForm.appendChild(pname);
   
var pprice = document.createElement("input");
    pprice.type = "hidden";
    pprice.name = "proprice";
    pprice.value = ppricevalue;   
    mapForm.appendChild(pprice);
    document.body.appendChild(mapForm);
    mapForm.submit();

return true;
}
</script>

<input type="hidden" id="<?php echo 'prname'.$formcounter?>" name="<?php echo 'pro'.$formcounter?>" value="<?php echo $productArray['Productname']?>">
<input type="hidden" id="<?php echo 'prprice'.$formcounter?>" name="<?php echo 'pro'.$formcounter?>" value="<?php echo $productArray['Price']; ?>">


<a href="javascript:return void(0);" onclick="javascript: return postdatasend('<?php echo $formcounter?>');"> send data</a>

Wednesday, November 14, 2012

shopping.com api using php and xml parsing easily

#create a array pagination class page.
<?php


  class pagination
  {
    var $page = 1; // Current Page
    var $perPage = 10; // Items on each page, defaulted to 10
    var $showFirstAndLast = false; // if you would like the first and last page options.
   
    function generate($array, $perPage = 10)
    {
      // Assign the items per page variable
      if (!empty($perPage))
        $this->perPage = $perPage;
     
      // Assign the page variable
      if (!empty($_GET['page'])) {
        $this->page = $_GET['page']; // using the get method
      } else {
        $this->page = 1; // if we don't have a page number then assume we are on the first page
      }
     
      // Take the length of the array
      $this->length = count($array);
     
      // Get the number of pages
      $this->pages = ceil($this->length / $this->perPage);
     
      // Calculate the starting point
      $this->start  = ceil(($this->page - 1) * $this->perPage);
     
      // Return the part of the array we have requested
      return array_slice($array, $this->start, $this->perPage);
    }
   
    function links()
    {
      // Initiate the links array
      $plinks = array();
      $links = array();
      $slinks = array();
     
      // Concatenate the get variables to add to the page numbering string
      if (count($_GET)) {
        $queryURL = '';
        foreach ($_GET as $key => $value) {
          if ($key != 'page') {
            $queryURL .= '&'.$key.'='.$value;
          }
        }
      }
     
      // If we have more then one pages
      if (($this->pages) > 1)
      {
        // Assign the 'previous page' link into the array if we are not on the first page
        if ($this->page != 1) {
          if ($this->showFirstAndLast) {
            $plinks[] = ' <a href="?page=1'.$queryURL.'">&laquo;&laquo; First </a> ';
          }
          $plinks[] = ' <span class="paginationPrev"><a href="?page='.($this->page - 1).$queryURL.'">&laquo; Prev</a></span> ';
        }
       
        // Assign all the page numbers & links to the array
        echo '<span nowrap="nowrap" align="center">';
        for ($j = 1; $j < ($this->pages + 1); $j++) {
          if ($this->page == $j) {
            $links[] = ' <span class="selected1">'.$j.'</span> '; // If we are on the same page as the current item
          } else {
            $links[] = ' <a href="?page='.$j.$queryURL.'">'.$j.'</a>'; // add the link to the array
          }
        }
        echo '</span>';
  echo '<span class="paginationNext">';
        // Assign the 'next page' if we are not on the last page
        if ($this->page < $this->pages) {
          $slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Next &raquo; </a> ';
          if ($this->showFirstAndLast) {
            $slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last &raquo;&raquo; </a> ';
          }
        }
        echo '</span>';
        // Push the array into a string using any some glue
        return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
      }
      return;
    }
  }
?>

-------------------------------End pagination class-----------------------------------------

#include pagination class 

#shopping.com api implement using php(shopapi.php) ;
<div class="proright">

<?php
 include('php_array_pagingnation.php');
$requey=$_REQUEST['categoryname'];

$response = new SimpleXMLElement(
    "http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword=$requey&numItems=1000",
    null,
    true
);

echo "<pre>";print_r($response);
?>

<div class="main_cart">
<?php
echo "<span style=\"padding-left:5px;\"><h2>$requey</h2></span>";
//print_r($response);
$pagination = new pagination;
  foreach ($response->categories->category->items->product as $value) {
          $products[] = array(
            'Productname' => $value->name,
            'productOffersURL' => $value->productOffersURL,
            'sourceURL' => $value->images->image->sourceURL,
            'storeNotes' => $value->numStores,
            'Price' => $value->minPrice,
             'reviewURL' => $value->rating->reviewURL,
            'reviewCount' => $value->rating->reviewCount,
            'ratingImage' => $value->rating->ratingImage->sourceURL,
          );
        }
       
        // If we have an array with items
        if (count($products)) {
          // Parse through the pagination class
          $productPages = $pagination->generate($products, 40);
          // If we have items
          if (count($productPages) != 0) {
            // Create the page numbers
            echo $pageNumbers = '<div class="paginationNew"><div class="numbers">'.$pagination->links().'</div></div>';
            // Loop through all the items in the array
foreach ($productPages as $productArray) {?>
     
             
                <div class="cart_det">
                <a href="<?php echo $productArray['productOffersURL']; ?>" target="_blank"><img src="<?php echo $productArray['sourceURL']; ?>" width="152" height="150"/></a>
                <div class="name"> <a href="<?php echo $productArray['productOffersURL']; ?>" target="_blank"><?php echo $productArray['Productname']; ?></a></div>
                <ul class="rate_det">
                <li class="price">From $<?php echo $productArray['Price']; ?></li>
                <li class="shiping">Free Shipping</li>
                <li class="story" ><?php echo $productArray['storeNotes']; ?> stores</li>
                 <li class="reviewno" >
                <?php if(!empty($productArray['reviewURL'])){?>
                  <a href="<?php echo $productArray['reviewURL']; ?>" target="_blank">Reviews (<?php echo $productArray['reviewCount']; ?>) </a>           
                <?php }else{?>&nbsp;
                    <?php }?>
                </li> 
                <li class="ratingimg">   
                <?php if(!empty($productArray['ratingImage'])){?>
                   
                <img src="<?php echo $productArray['ratingImage']; ?>" border="0" width="91">               
                               
                <?php }else{?>
                    <img src="images/sdc_stars_sm_blnk.gif" border="0" width="91">       
                    <?php }?>
                </li>
                </ul>
               
                </div>
        
            <?php }
            // print out the page numbers beneath the results
      
          }
         
        }


?>
</div>

<?php echo $pageNumbers = '<div class="numbers">'.$pagination->links().'</div>';?>

</div>

Sunday, November 11, 2012

how to add rows number using mysql query


select @rownum:=@rownum+1 ‘rowid’, p.* from menu p,  
(SELECT @rownum:=0) r order by id desc limit 10;

Thursday, November 8, 2012

create dynamic main menu and sub menu using php and mysql

<?php
CREATE TABLE `menu` (
  `id` int(11) NOT NULL auto_increment,
  `label` varchar(50) NOT NULL default '',
  `link` varchar(100) NOT NULL default '#',
  `parent` int(11) NOT NULL default '0',
  `sort` int(11) default NULL,
  PRIMARY KEY  (`id`))
------------------------------------------------------------------------------------------------------
$mysql=mysql_connect('127.0.0.1','root','');
mysql_select_db('test',$mysql);
function display_menu($parent, $level) {
    $result = mysql_query("SELECT a.id, a.label, a.link, Deriv1.Count FROM `menu` a  LEFT OUTER JOIN (SELECT parent, COUNT(*) AS Count FROM `menu` GROUP BY parent) Deriv1 ON a.id = Deriv1.parent WHERE a.parent=" . $parent);
    echo "<ul>";
    while ($row = mysql_fetch_assoc($result)) {
        if ($row['Count'] > 0) {
            echo "<li><a href='" . $row['link'] . "'>" . $row['label'] . "</a>";
            display_menu($row['id'], $level + 1);
            echo "</li>";
        } elseif ($row['Count']==0) {
            echo "<li><a href='" . $row['link'] . "'>" . $row['label'] . "</a></li>";
        } else;
    }
    echo "</ul>";
}
display_menu(0, 1);
?>

Tuesday, November 6, 2012

how to set custom page title in wordpress

 how to set custom page title in wordpress
<?php
function add_custom_title() {


         <title>call bikash page title</title>


}
add_action('wp_head','add_custom_title');
?>