Tuesday, 26 July 2016

Simple Pagination Logic

mysql_connect('localhost','root','');
mysql_select_db('Test');
$perpage=5;
$totalpage=mysql_num_rows(mysql_query('SELECT * FROM pagination'));
$pagination=ceil($totalpage/$perpage);

-------------------------------------------------------------------------------------------------------------------

if(isset($_GET['page']))
{
    $page=$_GET['page'];
}
else
(
    $page=1
);
$startfrom=($page-1)*$perpage;
$fnal_query ='SELECT * FROM pagination LIMIT '.$startfrom.','.$perpage ;
$result=mysql_query($fnal_query);

---------------------------------------------------------------------------------------------------------------------

for($i=1;$i<=$pagination;$i++)
  {?>
    <a href="<?php echo '?page='.$i;?>">
      <?php echo $i; ?>
      </a>
<?php }?>

PHP Image size is less than 1mb

1MB == 1048576 bytes

1MB == 1024 Kbytes

if($_FILES['name']['size'] > 1048576){
  //You can not upload this file
}

 

Wednesday, 6 April 2016

Set currency format for textbox on Keyup

Enter the numbers into textbox and textbox would convert automatically these number into currency.(12,345,654)

<script>
 function Comma(Num) { //function to add commas to textboxes
        Num += '';
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        x = Num.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1))
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        return x1 + x2;
    }
</script>
<input type="text" maxlength="20" class="" id="demo-number-value" value="" onkeyup = "javascript:this.value=Comma(this.value);"/>

Thursday, 17 March 2016

Show Dynamic RSS Feed on Your Website

RSS (Really Simple Syndication) feeds offer a method for normal guests of your web site to remain knowing of your most up-to-date content. you'll begin a brand new RSS feed, betting on your website, through such places as Feedburner. guests will then add your RSS feed to their Google Reader or as a appliance on their iGoogle pages. you'll conjointly add your RSS feed to your own website to form an automatic suggests that to showcase your latest content. you'll conjointly use services like HootSuite to push your RSS feed bent on places like Twitter, Facebook and lots of alternative social networking sites.

The purpose of this text is to indicate alternative ways on a way to gift RSS feeds on your website. this could be a really effective thanks to offer recent content to your readers. The content doesn’t even essentially have to be compelled to be your own, you'll use feeds from totally different sites in addition, however it’s best to use relevant content to your website.

header("Content-Type: application/rss+xml; charset=ISO-8859-1");

// Include your normal database connection file
require("connectdb.inc.php");

$sql2 = "SELECT * FROM blog WHERE status = '1' ORDER BY blogID DESC";
$query =mysql_quert($sql2);

$rssfeed = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>Fashion And Lifestyle Blog By Sonal Agrawal</title>';
$rssfeed .= '<link>http://www.pinkpeppercorn.in</link>';
$rssfeed .= '<description>A fashion and beauty blog that inspires readers to create the perfect wardrobe with essential styling tips by Sonal Agrawal</description>';
$rssfeed .= '<language>en-us</language>';

while($row=mysql_fetch_array($query)){
    $title=$row['blogTitle'];
    $link=$row['seoUri'];
    $description=$row['synopsis'];
  
    $rssfeed .= '<item>';
    $rssfeed .= '<title>' . $title . '</title>';
    $rssfeed .= '<description>' . $description . '</description>';
    $rssfeed .= '<link>http://www.example.in/blog/' . $link . '/'.$row['blogID'].'</link>';
    $rssfeed .= '<pubDate>' . date("D, d M Y H:i:s O", strtotime($row['dateAdded'])) . '</pubDate>';
    $rssfeed .= '</item>';  
}
    $rssfeed .= '</channel>';
    $rssfeed .= '</rss>';

   echo $rssfeed;

Friday, 4 March 2016

Get Category and Subcategory Hierarchy From Ebay

You can get the updated category and subcategory list from Ebay !

  • Create the application on http://developer.ebay.com
  • Generate the Appid
  • Copy Appid and paste below
NOTE :-
$url= 'http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid=APPID&siteid=203&CategoryID=-1&version=729&IncludeSelector=ChildCategories';
    $sXML = download_page($url);
    $oXML = simplexml_load_string($sXML);
    $cat_id=array();
    foreach($oXML->CategoryArray->Category as $category)
    {
        if($category->CategoryID!="-1")
        {
            $category->CategoryName;
            $category->CategoryID;
        }
    }
 

Monday, 28 December 2015

Recent Product History Script in PHP For Shopping Cart

<?php
    @session_start();
    if(!isset($_SESSION["lastviewed"]))    
    {
      $_SESSION["lastviewed"] = array();
    }
   
    $maxelements = 5;
    if(isset($_GET['ProductID']) && $_GET['ProductID']<>"")
    {// if we have url parameter
   
        if (in_array($_GET['ProductID'],$_SESSION["lastviewed"]))
        { // if product id is already in the array
            $_SESSION["lastviewed"] = array_diff($_SESSION["lastviewed"],array($_GET['ProductID'])) ; // remove it
            $_SESSION["lastviewed"] = array_values($_SESSION["lastviewed"]); //optionally, re-index the array
        }
   
        if(count($_SESSION["lastviewed"]) >= $maxelements)
        {//check the number of array elements
            $_SESSION["lastviewed"] = array_slice($_SESSION["lastviewed"],1); // remove the first element if we have 5 already
            array_push($_SESSION["lastviewed"],$_GET['ProductID']);//add the current itemid to the array
        }
        else
        {
            array_push($_SESSION["lastviewed"],$_GET['ProductID']);//add the current itemid to the array
        }
    }
   
    echo "<pre>";
    print_r($_SESSION["lastviewed"]);

?>


Wednesday, 4 November 2015

MySQL ordering results by specific field values

In MySQL we can sort the results in ascending or descending order very easily by using the ORDER BY clause. However, there are times when you want to sort the results in a specific order which cannot be done using the ASC or DSC. FIELD() of MySQL ORDER BY clause can be used to sort the results in a specific order.

You can use ORDER BY and FIELD function

SELECT * FROM table ORDER BY FIELD(ID,1,5,4,3)
 
 

Thursday, 24 September 2015

move_uploaded_file ( ) - Move an uploaded file Sample

/* get file name here */
        $file_name=$_FILES['profile_img']['name'];
        $file_temp_name=$_FILES['profile_img']['tmp_name'];
       
        $path_name="profile/".$file_name;
       
        if($_FILES['profile_img']['error']>0)
        {
            echo "Return Code : ".$_FILES['profile_img']['error']."</br>";
        }
        else
        {
            $allowed =  array('gif','png' ,'jpg');
            $filename = $_FILES['profile_img']['name'];
            $ext = pathinfo($filename,PATHINFO_EXTENSION);
            if(!in_array($ext,$allowed))
            {
                echo 'File is not allowed';
            }
            else
            {
                /* Move file here */
                $move_result=move_uploaded_file($file_temp_name,$path_name);
                if($move_result==TRUE)
                {
                    /*  Write your success code here */   
                }
        }

Javascript Validation While Image Uploading

<script>
function Checkfiles()
{
    var fup = document.getElementById('profile_img');
    var fileName = fup.value;
    var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
    if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "doc")
    {
        return true;
    }
    else
    {
        document.getElementById("err_profile_img").innerHTML="Upload a valid image";
        return false;
    }
}
</script>

<input type="file" name="profile_img" id="profile_img" onchange="Checkfiles()"/>