Translate

Monday 3 November 2014

Generate Reference Number Using PHP

Explaination:

In this tutorial i have explained the way of Generate Reference Number Using PHP.In this tutorial  using PHP to generete reference number for
 the easily way to generate without using any library files.By generating the reference number using the date function date("Y-m-d") and compare
 the date function into DB field is Createdon using LIKE '$temp_date%' Like function (i.e,,the date function have to stored one variable that
 function have to take it into LIKE function).Then we have to count the rows using mysql_num_rows and we have to add +1 to that counted variable.
 $value=$count+1 then finally have to generate reference number using str_pad conditon $refno=str_pad($value, 3, "0", STR_PAD_LEFT) for using STR_PAD_LEFT
 is adding the three "0"'s in left-side $value is counted values.Then lastly $reference = 'any_values'.date("ymd").$refno.I hope This Tutorial is very 
 helpfull for the Developers.

Coding:

 Syntax:str_pad(string,length,pad_string,pad_type)

Generate Reference Number:


<?php 
       $temp_date = date("Y-m-d");  
      $selecting = "SELECT * From `tblname` WHERE createdon LIKE '$temp_date%' ";
       $result = mysql_query($selecting);
       $fetching=mysql_fetch_array($result);
       $creat=$fetching['createdon'];
       $count = mysql_num_rows($result);
       $value = $count+1;
       $refno = str_pad($value, 3, "0", STR_PAD_LEFT);
       $reference_number = 'NNT'.date("ymd").$refno;
       ?>

No comments:

Post a Comment