Friday 25 December 2020

Tuesday 8 December 2020

Online Attendance System Using PHP

 Online Attendance System Using PHP

DATABASE: online_attendance

Table: Attendance



Table: member



____________________________________________

Create Below PHP Files

Connection File: z_db.php

<?php
$con=mysqli_connect("localhost","root","","online_attendance");
?>

___________________________________________

menu.php


<style type="text/css">
.menu{
color: white;
background-color: black;
padding: 10px;
font-size: 1.3em;
text-decoration: none;
}
.menu:hover{
color: tomato;
background-color: yellow;
padding: 10px;
box-shadow: 5px 4px 5px 1px;
}
</style>
<ul style="list-style:none;display:inline-block">
<li style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php" class="menu">Add Member</a>&nbsp;&nbsp;&nbsp;&nbsp;</li>
    <li style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;<a href="getattendance.php" class="menu">Get Attendance</a>&nbsp;&nbsp;&nbsp;&nbsp;</li>
    <li style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;<a href="printreport.php" class="menu">Print Report</a>&nbsp;&nbsp;&nbsp;&nbsp;</li>
    <li style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;<a href="viewmember.php" class="menu">View Member</a>&nbsp;&nbsp;&nbsp;&nbsp;</li>
</ul>

__________________________________________

footer.php



<div style="background-color: black; color: white; font-size: 1.4em; padding: 12px; text-align: center;">Design & Developed By: Avadh Tutor</div>
<div style="background-color: tomato; color: white; font-size: 1.6em; padding: 10px; text-align: center;">

<marquee>
Learn All Programming languages with youtube.com/avadhtutor
</marquee>

</div>
<div style="background-color: black; color: white; font-size: 1.4em; padding: 10px; text-align: center;">All Examples inside pandyaripal.blogspot.com</div>



_________________________________________

index.php



<title>Online Attendance - Avadh Tutor</title><style type="text/css">
<!--
.style1 {
font-family: "Courier New", Courier, monospace;
font-size: 60px;
color: #FFFFFF;
font-style: italic;
}
.style2 {
font-size: 24px;
color: #0000FF;
}
.style6 {font-size: 16px}
-->
</style></head>

<body>
<table width="800" border="1" align="center">
      <tr>
        <td bordercolor="#330033" bgcolor="#CCCCFF"><h1 align="center"><strong><span class="style1">Attendance System</span></strong></h1></td>
      </tr>
      <tr>
        <td bgcolor="#999966"><div align="center">
        <?php 
include "menu.php";
?> 
        </div>       </td>
      </tr>
      <tr>
        <td><div align="center">
        <form action="insertmember.php" method="post">
          <table width="400" border="2" align="center" bordercolor="#9966FF" bgcolor="#C7B6B1">
            <tr>
              <td colspan="2" bgcolor="#9999CC"><div align="center"><strong><span class="style2">Enter the member information</span></strong></div></td>
            </tr>
            <tr>
              <td width="160"><span class="style6">Name</span></td>
              <td width="222"><span class="style6"><input type="text" name="name" /></span></td>
            </tr>
            <tr>
              <td><span class="style6">Mobile</span></td>
              <td><span class="style6"><input type="text" name="mobile" /></span></td>
            </tr>
            <tr>
              <td><span class="style6">Email</span></td>
              <td><span class="style6"><input type="email" name="email" /></span></td>
            </tr>
            <tr>
              <td colspan="2"><div align="center">
                <input type="submit" value="Add Member" name="btnsubmit"/>
                &nbsp;&nbsp;
                <input type="reset" value="Reset" name="btnreset"/>
              </div></td>
            </tr>
          </table>
          </form>
        </div></td>
      </tr>
    </table>
<?php include "footer.php"; ?>
</body>
</html>


__________________________________________________

insertmember.php



<?php
if(isset($_POST["btnsubmit"]))
{
extract($_POST);
include "z_db.php";
if($rec=mysqli_fetch_array(mysqli_query($con,"SELECT member_id FROM `member` order by member_id desc limit 1")))
{
$bid =1+ $rec['member_id'];
}
$en = date("Y").$bid;
$query = "INSERT INTO  `member`(`enrolment_no` ,  `name` ,  `mobile` ,  `email`) VALUES('$en','$name','$mobile','$email')";

$q = mysqli_query($con,$query)or die("insert error");
print "<script>";
print "alert('Member add successfully....');";
print "self.location='index.php';";
print "</script>";
}
else
{
header("Location:index.php");
}
?>
<?php include  "footer.php"; ?>



____________________________________________________

getattendance.php




<title>Simple Online Attendance System - Avadh Tutor</title><style type="text/css">
<!--
.style1 {
font-family: "Courier New", Courier, monospace;
font-size: 60px;
color: #FFFFFF;
font-style: italic;
}
.style2 {
font-size: 24px;
color: #0000FF;
}
.style7 {color: #FFCCFF}
-->
</style>
<script type="text/javascript">
function getatt(value)
{
if(value == true)
{
document.getElementById("txtAbsent").value = parseInt(document.getElementById("txtAbsent").value) - 1;
document.getElementById("txtPresent").value = parseInt(document.getElementById("txtPresent").value) + 1;
}
else
{
document.getElementById("txtAbsent").value = parseInt(document.getElementById("txtAbsent").value) + 1;
document.getElementById("txtPresent").value = parseInt(document.getElementById("txtPresent").value) - 1;
}
}
</script>


<table width="800" border="1" align="center">
      <tr>
        <td bordercolor="#330033" bgcolor="#CCCCFF"><h1 align="center"><strong><span class="style1">Attendance System</span></strong></h1></td>
      </tr>
      <tr>
        <td bgcolor="#999966"><div align="center">
        <?php 
include "menu.php";
?> 
        </div>       </td>
      </tr>
      <tr>
        <td>
        <form action="getattendance1.php" method="post">
        <table width="180px" align="left" style="">
            <tr>
                <td> Select date : <br />
                   <?php 
    $dt = getdate();
$day = $dt["mday"];
$month = date("m");
$year = $dt["year"];
echo "<select name='cdate'>";
for($a=1;$a<=31;$a++)
{
if($day == $a)
echo "<option value='$a' selected='selected'>$a</option>";
else
echo "<option value='$a' >$a</option>";
}
echo "</select><select name='cmonth'>";
for($a=1;$a<=12;$a++)
{
if($month == $a)
echo "<option value='$a' selected='selected'>$a</option>";
else
echo "<option value='$a' >$a</option>";
}
echo "</select><select name='cyear'>";
for($a=2010;$a<=$year;$a++)
{
if($year == $a)
echo "<option value='$a' selected='selected'>$a</option>";
else
echo "<option value='$a' >$a</option>";
}
echo "</select>";
?>                    
                    </td>
                </tr>
             </table>
        
          <table width="400" border="2" align="left" bordercolor="#9966FF" bgcolor="#C7B6B1" style="margin-left:20px;">
            <tr>
              <td colspan="3" bgcolor="#9999CC"><div align="center"><strong><span class="style2">Get Attendance</span></strong></div></td>
            </tr>
            <tr bgcolor="#999966">
              <td width="114"><span class="style7">Enrolment no</span></td>
              <td width="152"><span class="style7">Name</span></td>
              <td width="110"><span class="style7">Attend</span></td>
            </tr>
            <?php
include "z_db.php";
extract($_POST);
$query = "select *from `member` order by `member_id`";
$s = 0;
$result = mysqli_query($con,$query)or die("select error");
while($rec = mysqli_fetch_array($result))
{
$s = $s + 1;
echo ' <tr>
  <td width="114">'.$rec["enrolment_no"].'</td>
  <td width="152">'.$rec["name"].'</td>
  <td width="110"><input type=checkbox name='.$rec["member_id"].' onclick="getatt(this.checked);"/></td>
</tr>';
}
?>
            <tr>
              <td colspan="3"><div align="center">
                <input type="submit" value="Get Attendance" name="btnsubmit"/>
                &nbsp;&nbsp;</div></td>
            </tr>
          </table>
          </form>
         
          <table width="100px" align="right" style="margin-left:35px">
            <tr>
                <td> Total Absent : <input type="text" id="txtAbsent" value="<?php print $s; ?>" size="10" disabled="disabled"/></td>
                </tr>
                <tr>
                <td> Total Present : <input type="text" id="txtPresent" value="0" size="10"  disabled="disabled"/></td>
                </tr>
                <tr>
                <td> Total Strength : <input type="text" id="txtStrength" value="<?php print $s; ?>" size="10" disabled="disabled"/></td>
                </tr>
             </table>
         
         </td>
      </tr>
    </table>

<?php include  "footer.php"; ?>


________________________________________________

getattendance1.php





<?php
if(isset($_POST["btnsubmit"]))
{
include "z_db.php";
$date = $_POST["cyear"]."-".$_POST["cmonth"]."-".$_POST["cdate"];
               
$query = "select *from `member` ";
$result = mysqli_query($con,$query)or die("select error");
while($rec = mysqli_fetch_array($result))
{
$mno = $rec["member_id"];
if(isset($_POST[$mno]))
{
$query1 = "INSERT INTO  `attandance`(`member_id` ,  `date` ,  `attendance`) VALUES('$mno','$date','1')";
}
else
{
$query1 = "INSERT INTO  `attandance`(`member_id` ,  `date` ,  `attendance`) VALUES('$mno','$date','0')";
}
mysqli_query($con,$query1)or die("insert error".$mno);
print "<script>";
print "alert('Attendance get successfully....');";
print "self.location='getattendance.php';";
print "</script>";
}
}
else
{
header("Location:index.php");
}
?>

<?php include "footer.php"; ?>


_____________________________________________________

printreport.php



<title>Online Attendance - Avadh Tutor</title>
<style type="text/css">
<!--
.style1 {
font-family: "Courier New", Courier, monospace;
font-size: 60px;
color: #FFFFFF;
font-style: italic;
}
.style2 {
font-size: 24px;
color: #0000FF;
}
.style6 {font-size: 16px}
-->
</style>
<table width="800" border="1" align="center">
      <tr>
        <td bordercolor="#330033" bgcolor="#CCCCFF"><h1 align="center"><strong><span class="style1">Attendance System</span></strong></h1></td>
      </tr>
      <tr>
        <td bgcolor="#999966"><div align="center">
        <?php 
include "menu.php";
?> 
        </div>       </td>
      </tr>
      <tr>
        <td><div align="center">
        <form action="" method="post">
          <table width="606" border="2" align="center" bordercolor="#9966FF" bgcolor="#C7B6B1">
          <tr><td colspan="3" align="center"><h3>Search Enrolment No Wise Records Here</h3></td></tr>
            <tr>
              <td width="308" bgcolor="#9999CC"><div align="center"><strong><span class="style2">Enter the enrolment no</span></strong></div></td>
              <td width="144" bgcolor="#9999CC"><span class="style6">
                <input type="text" name="eno" />
              </span></td>
              <td width="130" bgcolor="#9999CC"><input type="submit" value="View Information" name="btnsubmit"/></td>
            </tr>
          </table>
          </form>
        </div></td>
      </tr>
<?php
if(isset($_POST["btnsubmit"]))
{
include "z_db.php";
extract($_POST);
$query = "select * from `member` where enrolment_no = ".$eno." limit 1";

$result = mysqli_query($con,$query)or die("select error error");
while($rec = mysqli_fetch_array($result))
{
echo '<tr><td colspan="2"><table width="400" border="2" align="center" bordercolor="#9966FF" bgcolor="#C7B6B1">
<tr>
  <td width="160" bgcolor="#9999CC"><span class="style2">Enrolment No</span></td>
  <td width="160" bgcolor="#9999CC"><span class="style2">Name</span></td>';
  $query1 = "select * from `attandance` where `member_id` = ".$rec["member_id"]." order by date";
$result1 = mysqli_query($con,$query1)or die("select error error");
while($rec1 = mysqli_fetch_array($result1))
{
  echo '<td bgcolor="#9999CC" class=style2>'.$rec1["date"].'</td>';
}
echo '</tr>
<tr>
  <td width="222"><span class="style6">'.$rec["enrolment_no"].'</span></td>
  <td width="222"><span class="style6">'.$rec["name"].'</span></td>';
  $query1 = "select *from `attandance` where `member_id` = ".$rec["member_id"]." order by date";
$result1 = mysqli_query($con,$query1)or die("select error error");
while($rec1 = mysqli_fetch_array($result1))
{
  echo '<td>';
if($rec1["attendance"]==0)
echo "Absent";
else
echo "Present";
echo '</td>';
}
echo '
</tr>
  </table></td></tr>';
}
}
else
{
include "z_db.php";
extract($_POST);
$query = "select * from `member` ";

$result = mysqli_query($con,$query)or die("select error error");
while($rec = mysqli_fetch_array($result))
{
echo '<tr><td colspan="2"><table width="90%" border="2" align="center" bordercolor="#9966FF" bgcolor="#C7B6B1">
<tr>
  <td width="160" bgcolor="#9999CC"><span class="style2">Enrolment No</span></td>
  <td width="160" bgcolor="#9999CC"><span class="style2">Name</span></td>';
  $query1 = "select * from `attandance` where `member_id` = ".$rec["member_id"]." order by date";
$result1 = mysqli_query($con,$query1)or die("select error error");
while($rec1 = mysqli_fetch_array($result1))
{
  echo '<td bgcolor="#9999CC" class=style2>'.$rec1["date"].'</td>';
}
echo '</tr>
<tr>
  <td width="222"><span class="style6">'.$rec["enrolment_no"].'</span></td>
  <td width="222"><span class="style6">'.$rec["name"].'</span></td>';
  $query1 = "select *from `attandance` where `member_id` = ".$rec["member_id"]." order by date";
$result1 = mysqli_query($con,$query1)or die("select error error");
while($rec1 = mysqli_fetch_array($result1))
{
  echo '<td>';
if($rec1["attendance"]==0)
echo "Absent";
else
echo "Present";
echo '</td>';
}
echo '
</tr>
  </table></td></tr>';
}
}
?>    
</table>
<?php include "footer.php"; ?>

_________________________________________________

viewmember.php



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Online Attendance System - Avadh Tutor</title><style type="text/css">
<!--
.style1 {
font-family: "Courier New", Courier, monospace;
font-size: 60px;
color: #FFFFFF;
font-style: italic;
}
.style2 {
font-size: 24px;
color: #0000FF;
}
.style6 {font-size: 16px}
-->
tr{

}
tr:hover{
background-color: yellow;

}
</style></head>

<body>
<table width="800" border="1" align="center">
      <tr>
        <td bordercolor="#330033" bgcolor="#CCCCFF"><h1 align="center"><strong><span class="style1">Attendance System</span></strong></h1></td>
      </tr>
      <tr>
        <td bgcolor="#999966"><div align="center">
        <?php 
include "menu.php";
?> 
        </div>       </td>
      </tr>
      
      <tr style="background-color: white;"><td colspan="2">
        <form action="" method=post>
        
        <table width="500" border="2" align="center" cellpadding="5" cellspacing="10" bordercolor="#9966FF" bgcolor="#C7B6B1">
        <tr>
  <td colspan="5" bgcolor="#9999CC"><div align="center"><strong><span class="style2">Member information</span></strong></div></td>
</tr>
            <tr>
  <td  bgcolor="#9999CC"><div align="center"><strong><span class="style2">Enrolment No</span></strong></div></td>
                  <td  bgcolor="#9999CC"><div align="center"><strong><span class="style2">Name</span></strong></div></td>
                  <td  bgcolor="#9999CC"><div align="center"><strong><span class="style2">Mobile</span></strong></div></td>
                  <td  bgcolor="#9999CC"><div align="center"><strong><span class="style2">Email</span></strong></div></td>
                  <td  bgcolor="#9999CC"><div align="center"><strong><span class="style2">Delete</span></strong></div></td>
</tr>
<?php
include "z_db.php";
$query = "select *from `member` ";

$result = mysqli_query($con,$query)or die("select error error");
while($rec = mysqli_fetch_array($result))
{
echo '<tr height=30px>
  <td width="222"><span class="style6">'.$rec["enrolment_no"].'</span></td>
  <td width="222"><span class="style6">'.$rec["name"].'</span></td>
  <td width="222"><span class="style6">'.$rec["mobile"].'</span></td>
  <td width="222"><span class="style6">'.$rec["email"].'</span></td>
  <td width="222"><span class="style6">';
  echo '<a style="background-color:#CCCCCC;color:#CC3333;border:solid;text-decoration:none;border-radius:10px;position:relative;top:0px;border-color:red;" href="deletemember.php?d='.$rec["member_id"].'">&nbsp;Delete&nbsp;</a></span></td></tr>';   
}
?>    
        </table>
        </form>
        </td>
        </tr>
</table>
    
<?php include "footer.php"; ?>


________________________________________________________

deletemember.php



<?php
include_once "z_db.php";
mysqli_query($con,"DELETE FROM `member` WHERE `member_id` = ".$_GET["d"]." LIMIT 1;") or die("Delete member error");
print "<script>";
print "alert('Member Deleted succesfully.....');";
print " self.location='viewmember.php';"; // Comment this line if you don't want to redirect
print "</script>";
?>
<?php
include "footer.php";
?>


_______________________________________________________

Thanks for watch Our Blog


Learn All Programming and Scripting Languages with youtube.com/avadhtutor

_____________________________________________________






Monday 7 December 2020

Simple Difference Between HTML vs CSS Program

 HTML V/s CSS Simple Program


Save this file as a 1.html

_____________________________________

<!-- HTML -->

<p bgcolor=red> welcome 123</p> <!-- Not Supported By HTML -->

<!-- CSS -->

<p style="background-color:red; ">welcome</p> <!-- Using CSS Background Attribute -->


<br>

<marquee bgcolor=red>welcome</marquee>

<br><br>

<!-- CSS -->

<a href="" style="text-decoration:none;">Home</a> <!-- remove Underline from link -->


<br><br>

<!-- HTML -->

<a href=""><font color=orange><b>Contact Us</b></font></a> 


<br><br>

<!-- CSS -->

<a href="" style="color:orange; text-decoration:none; ">Contact Us</font>


Copy and Past This Code inside a 1.html file and run it to your browser

Learn All programming and Scripting languages with youtube.com/avadhtutor/







no exports found that matches the constraint

Sunday 22 November 2020

PHP ACCESS MODIFIER - Public Private and Protected

  Public Private and Protected Using PHP OOP

What is Public Keyword in PHP:

the public property, Variable  or method can be accessed from everywhere that's called as Public

Example:

<?php

/* Public Keyword*/

class pri

{

    public $name='Public Work';  // A public variable

}

class pritwo extends pri // Inherited class

{

//private Not worked

function display()

    {

        return $this->name; 

    }

    

}

$s = new pritwo;

echo "<font color=red>".$s->display()."</font>"; 


$o = new pri;

echo "<font color=green>".$o->name."<font>"; 

?>

___________________________________________________________________

Private Keyword:

The private keyword  that the declared property/method can only be accessed within the class

Private Keyword will be access in only limited scope
Example :

<?php
/* Private Keyword*/
class main
{
    private $name='Private Work';  // A public variable
function display()
    {
        return $this->name; 
    }
}
class second extends main // Inherited class
{
function display()
    {
        return $this->name; 
    }
}
$s = new second;
echo "<font color=red>".$s->display()."</font>"; 

$o = new main;
echo "<font color=green>".$o->name."<font>"; 

?>
____________________________________________________________

Protected Keyword:

Protected Properties can be access within a inherited class

the property can be accessed within the class and by classes derived from that class. 

private  the property or method can ONLY be accessed within the class.

Example:
<?php
/* Protected Keyword*/
class m
{
    protected $name='here Protected';  
}
class s extends m // Inherited class
{
function display()
    {
        return $this->name; 
    }
}
$s = new s;
echo "<font color=red>".$s->display()."</font>"; 

$o = new m;
echo "<font color=green>".$o->name."<font>"; 
?>

___________________________________________________________________

learn all the Programming and Scripting Languages with youtube.com/avadhtutor



Sunday 15 November 2020

Happy New Year Script Using CSS

Happy New Year Using CSS 

Create Files:

- avadh tutor.html

- back.jpg

- pattern.png

_____________________________________________________________________

avadh tutor.html

<style>

body

{

margin:0;

padding:0;

background:  url(back.jpg);

height: 100%; 


    /* Center and scale the image nicely */

    background-position: center;

    background-repeat: no-repeat;

    background-size: cover;

}

.banner

{

height:100vh;

}

.banner:before

{

content: '';

height:100vh;

width:100vw;

position:absolute;

top:0;

left:0;

background:  url(pattern.png);

animation: animate 10s linear infinite;

}

.text

{

color: #04619E;

font-size: 6.2em;

    width: 100%;

    text-align: center;

    text-shadow: 5px 5px 5px #B31DCE;

    font-family: Elephant;

    font-weight: bold;

}

.redtext

{

color: tomato;

font-size: 8.5em;

font-family: 'Bauhaus 93';

text-align: right;

width: 80%;

text-shadow: 5px 5px 10px rgb(0,0,0);


}

.from{

color: blue;

font-size: 3.6em;

text-align: right;

width: 80%;

font-family:Cooper;

text-shadow: 4px 5px 3px rgb(25,205,2);


}

.avadh{

color: black;

font-size: 1.2em;

width: 80%;

text-align: right;

}

@keyframes animate

{

 0%

 {

background-position: 0 0;

 }

 100%

 {


background-position : 0  550px;

  }


}

</style>


<div class="banner">

<div class="text">Happy New Year</div>

<div class="redtext">2020</div>

<div class="from">AvadhTutor - Ripal Pandya</div>

<div class="avadh">learn All Programming Languages inside youtube.com/avadhtutor </div>

</div>


_____________________________________________________________________

Right Click and save as Images :

back.jpg

Pattern.png


Learn all Programming Languages inside youtube.com/avadhtutor/



Wednesday 14 October 2020

What is Parameterized constructor in PHP? Explain with Example

Parameterized constructor 
  • Parameterized constructor is a constructor that accepts parameter and is normally used to initialize member variables at the time of object creation.
  • The constructor of the class accepts arguments or parameters
Example:

<form action="" method="post">
Enter Code:<input type="text" name="code" value="" /><br />
Enter Name:<input type="text" name="name" value="">
<br />
<input type="submit" name="sb" value="Click" />
</form>

<?php
//Paramiterrized Constructor
$code = $_POST['code'];
$name = $_POST['name'];
class Employee
{
var $empcode;
var $empname;
function Employee($code,$name)
/*class name and function name are same but different variable passed as known as a parameterized constructor*/
{
$this->empcode = $code;
$this->empname = $name;
}
function display()
{
echo " <h1><br>";
echo "<br> Employee Code : " . $this->empcode;
echo "<br> Employee Name : " . $this->empname;
echo "</h1>";
}
};
$object = new Employee($code,$name);

$object -> display();
?>

Thursday 8 October 2020

What is destructor? explain with example in php

 DESTRUCTOR

  • A destructor is called when the object is destroyed.
  • A destructor is a special method called automatically during the destruction of an object. Actions executed in the destructor include the following
    • Recovering the heap space allocated during the lifetime of an object
    • Closing file or database connections
    • Releasing network resources
    • Releasing resource locks
    • Other housekeeping tasks

Example of Constructor and Destructor:
<?php
class dclass
{
    public $name = "Youtube with Avadh Tutor";    
    public function __construct($name)
    {
        echo "<font color=blue>By default Constructor</font>";    
        $this->name = $name;
    }
    
    public function __destruct()
    {
        echo "<font color=orange>Class with destructor Call </font>";
//$this->name = $name; /*error*/
    }
}

$d = new dclass("Argument");
echo "<br><br>Name of the Channel: " . $d->name;
/* destruct call after object destroy*/
?>

Wednesday 30 September 2020

What is Constructor? Explain with Example

What is Constructor:

  • is a member function of a class which initializes objects of a class
  • If you create a __construct() function, PHP will automatically call this function when you create an object from a class.
  • Class name and method name are same that called as a constructor

Example: 

<?php
class Employee
{
var $empcode;
var $empname;
function Employee()
//not passed as a parameter
{
$this->empcode = 100;
$this->empname='avadh tutor';
}
function display()
{
echo "<h1><br>";
echo "<br>Emp Code = " . $this->empcode;
echo "<br>Emp Name = " . $this->empname;
echo "</h1>";
}
};
$instance = new Employee(); // Constructor automatically call
$instance -> display();
?>

How to Create Simple Class using PHP

What is Class in PHP

  • class is a container that can contain variables, constructors, functions etc.
  • This is a programmer-defined data type, which includes local functions as well as local data.
  • A class is a self-contained, independent collection of variables and functions which work together to perform one or more specific tasks, while objects are individual instances of a class.

Syntax:

class classname
{
variables
function functionname
{
--
}

}

class object
calling function
display function

Example: 

<?php
class student
{
//var $rollno;
//var $name;
function get()
{
$this->rollno = 10;
$this->name = 'raj';
}
function display()
{
echo "<pre><br>Roll No : " . $this->rollno;
echo "<br>Name : " . $this->name;
}
};
$obj = new student();
$obj->get();
$obj->display();
?>


Learn all the programming inside youtube.com/avadhtutor





Thursday 20 August 2020

how to create slider using android studio simple example

 how to create slider using android studio simple example

View Video: https://youtu.be/LUnA4JzQ_RE

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<androidx.viewpager.widget.ViewPager

android:id="@+id/view_pager"


android:layout_width="match_parent"

android:layout_height="match_parent"
android:background="@color/colorPrimary" />

<LinearLayout


android:id="@+id/layoutDots"


android:layout_width="match_parent"


android:layout_height="@dimen/dots_height"


android:layout_alignParentBottom="true"


android:layout_marginBottom="@dimen/dots_margin_bottom"


android:gravity="center"


android:orientation="horizontal"></LinearLayout>

<View


android:layout_width="match_parent"


android:layout_height="1dp"


android:layout_above="@id/layoutDots"


android:alpha=".20"


android:background="@android:color/white" />


<Button


android:id="@+id/btn_next"


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:layout_alignParentRight="true"


android:layout_alignParentBottom="true"


android:background="@null"


android:text="Next"


android:textColor="@android:color/white" />


<Button


android:id="@+id/btn_skip"


android:layout_width="wrap_content"


android:layout_height="wrap_content"


android:layout_alignParentLeft="true"


android:layout_alignParentBottom="true"


android:background="@null"


android:text="skip"


android:textColor="@android:color/white" />
</RelativeLayout>


MainActivity.java

package com.example.slider;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

ViewPager viewPager;
MyViewPagerAdapter myViewPagerAdapter;
LinearLayout linearLayout;
TextView[] dots;
static int[] dotalayout;
Button btnSkip,btnNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager=(ViewPager)findViewById(R.id.view_pager);
linearLayout=(LinearLayout)findViewById(R.id.layoutDots);
btnNext=(Button)findViewById(R.id.btn_next);
btnSkip=(Button)findViewById(R.id.btn_skip);

dotalayout=new int[]{
R.layout.screen1,R.layout.screen2,R.layout.screen3,R.layout.screen4
};
addbtn(0);
myViewPagerAdapter=new MyViewPagerAdapter(MainActivity.this);
viewPager.setAdapter(myViewPagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

}

@Override
public void onPageSelected(int position) {
addbtn(position);
if (position== dotalayout.length)
{
btnNext.setText("Start");
btnSkip.setVisibility(View.GONE);
}
else
{
btnNext.setText("NEXT");
btnSkip.setVisibility(View.VISIBLE);
}

}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}
public void addbtn(int CurrentPage)
{
dots=new TextView[dotalayout.length];
int [] colorActive=getResources().getIntArray(R.array.array_dot_active);
int [] colorInActive=getResources().getIntArray(R.array.array_dot_inactive);
linearLayout.removeAllViews();
for(int i=0;i< dots.length;i++)
{
dots[i]=new TextView(this);
dots[i].setText(Html.fromHtml("&#8226;"));
dots[i].setTextSize(35);
dots[i].setTextColor(colorInActive[CurrentPage]);
linearLayout.addView(dots[i]);
}
if(dots.length>0)
{
dots[CurrentPage].setTextColor(colorActive[CurrentPage]);
}
}
}

MyViewpageAdapter.java

package com.example.slider;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import static com.example.slider.MainActivity.dotalayout;

public class MyViewPagerAdapter extends PagerAdapter {
Context cx;
LayoutInflater layoutInflater;

public MyViewPagerAdapter(Context context) {
cx = context;
}

@Override
public int getCount() {
return dotalayout.length;
}

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {

layoutInflater = (LayoutInflater) cx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(dotalayout[position], container, false);
container.addView(view);
return view;
}

@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}

@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
View view=(View) object;
container.removeView(view);
}
}

layout/screen1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_screen1">

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center_horizontal"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:text="WELCOME"
android:textColor="@android:color/background_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />

<ImageView

android:layout_width="@dimen/img_width_height"


android:layout_height="@dimen/img_width_height"

android:src="@drawable/avadh" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"
android:text="AVADH TUTOR"

android:textColor="@android:color/holo_red_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />


</LinearLayout>

</RelativeLayout>


layout/screen2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_screen2">

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center_horizontal"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:text="All Languages"
android:textColor="@android:color/background_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />

<ImageView

android:layout_width="@dimen/img_width_height"


android:layout_height="@dimen/img_width_height"

android:src="@drawable/program" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"
android:text="Please Like and Share"

android:textColor="@android:color/holo_red_dark"

android:textSize="@dimen/slide_title"
android:textStyle="bold" />


</LinearLayout>

</RelativeLayout>

layout/screen3.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_screen3">
<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center_horizontal"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:text="WELCOME"
android:textColor="@android:color/background_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />

<ImageView
android:layout_width="@dimen/img_width_height"


android:layout_height="@dimen/img_width_height"

android:src="@drawable/blog" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"
android:text="Look Our Blog"

android:textColor="@android:color/holo_red_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />


</LinearLayout>


</RelativeLayout>

layout/screen4.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_screen4">

<LinearLayout

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:gravity="center_horizontal"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="50dp"

android:text="AVADH TUTOR"
android:textColor="@android:color/background_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />

<ImageView

android:layout_width="@dimen/img_width_height"


android:layout_height="@dimen/img_width_height"

android:src="@drawable/subscribe" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"
android:text="Lets Start"

android:textColor="@android:color/holo_red_dark"

android:textSize="@dimen/slide_title"

android:textStyle="bold" />


</LinearLayout>


</RelativeLayout>

values/ colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>

<color name="bg_screen1">#BDB883</color>
<color name="bg_screen2">#AAE6E1</color>
<color name="bg_screen3">#F4DDB9</color>
<color name="bg_screen4">#CAECA3</color>
<array name="array_dot_active">
<item>#F0E9A9</item>
<item>#ABEEE5</item>
<item>#F1C98D</item>
<item>#D4F1B1</item>
</array>
<array name="array_dot_inactive">
<item>#DFC90B</item>
<item>#0C917E</item>
<item>#BE7A15</item>
<item>#619C1D</item>
</array>
</resources>


Save Your Images inside drawable folder


View Video : https://youtu.be/LUnA4JzQ_RE