D3cryp73r

PHP_Script_for_getting_Year_of_ENG_Student

Sep 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "registration";
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7.  
  8. //Create Connection
  9. $conn = new mysqli($servername, $username, $password, $dbname);
  10. // Check connection
  11. if ($conn->connect_error) {
  12.     die("Connection failed: " . $conn->connect_error);
  13. }
  14.  
  15. $sql = "SELECT id,year FROM student";
  16. $result = $conn->query($sql);
  17.  
  18.  
  19. if (mysqli_num_rows($result) > 0)
  20. {
  21.     // output data of each row
  22.     $rowcount=mysqli_num_rows($result);
  23.     while($array = mysqli_fetch_assoc($result))
  24.     {
  25.         $mainId[]=$array["id"];
  26.         $mainYear[]=$array["year"];
  27.        
  28.     }
  29.    
  30. }
  31. else
  32. {
  33.     echo "0 results";
  34. }
  35. $sub=date('M Y');
  36. echo "\n";
  37. $presentYear=date('Y');   //2018
  38. $presentMon=date('m');    //Sepetember 09
  39. echo $presentMon;
  40. echo $presentYear;
  41.  
  42. //Calculating present year for all the students
  43. echo $rowcount; //Number of rows in sql result
  44. $row=4;
  45. echo "<br>".$presentYear."<br>";
  46. echo "Main year is ".$mainYear[0]."<br>";
  47.  
  48.  
  49. function calcuateonemonth($id)
  50. {
  51.    
  52.    
  53.     if($GLOBALS['presentMon']>=06)
  54.     {
  55.         echo "ID having ".$GLOBALS['temp']." is Firstyear <br>";
  56.     }
  57.     else
  58.     {
  59.        echo "ID having ".$GLOBALS['temp']." is Having Error <br>";
  60.     }
  61. }
  62. function calcuatetwomonth($id)
  63. {  
  64.     echo $id;
  65.     if($GLOBALS['presentMon']>=06)
  66.     {
  67.         echo "ID having ".$GLOBALS['temp']." is Secondyear <br>";
  68.     }
  69.     else
  70.     {
  71.          echo "ID having ".$GLOBALS['temp']." is Firstyear <br>";
  72.     }
  73. }
  74. function calcuatethreemonth($id)
  75. {
  76.    
  77.     if($GLOBALS['presentMon']>=06)
  78.     {
  79.       echo "ID having ".$GLOBALS['temp']." is Thirdyear<br>";
  80.     }
  81.     else
  82.     {
  83.         echo "ID having ".$GLOBALS['temp']." is Secondyear<br>";
  84.     }
  85. }
  86. function calcuatefourmonth($id)
  87. {
  88.  
  89.     if($GLOBALS['presentMon']>=06)
  90.     {
  91.       echo "ID having ".$GLOBALS['temp']." is Fourthyear<br>";
  92.     }
  93.     else
  94.     {
  95.          echo "Thirdyear";
  96.     }
  97.    
  98. }
  99. function calcuatefifthmonth($id)
  100. {
  101.    
  102.     if($GLOBALS['presentMon']<06)
  103.     {
  104.        echo "ID having ".$GLOBALS['temp']." is Thirdyear<br>";
  105.     }
  106.     else
  107.     {
  108.             echo "ID having ".$GLOBALS['temp']." is Having Error <br>";
  109.     }
  110. }
  111.  
  112.  
  113.  
  114.  
  115. for($i=0;$i<$rowcount;$i++)
  116. {
  117.     $temp=$mainId[$i];
  118.    if($presentYear==$mainYear[$i])
  119.    {
  120.       calcuateonemonth($i);
  121.    }
  122.     else if($presentYear==$mainYear[$i]+1)
  123.     {
  124.        calcuatetwomonth($i);
  125.     }
  126.     else if($presentYear==$mainYear[$i]+2)
  127.     {
  128.         calcuatethreemonth($i);
  129.     }
  130.      else if($presentYear==$mainYear[$i]+3)
  131.     {
  132.         calcuatefourmonth($i);
  133.     }
  134.      else if($presentYear==$mainYear[$i]+4)
  135.     {
  136.       calcuatefifthmonth($i);
  137.     }
  138.     else
  139.     {
  140.          echo "ID having ".$GLOBALS['temp']." is Having Error <br>";
  141.     }
  142.    
  143.    
  144. }
  145.  
  146. ?>
Add Comment
Please, Sign In to add comment