Monday, 25 July 2016

Pagination Tutorial for PHP MySQL Programmers





<html>
<head>

<style>
.pagNumActive{
color:#000;
border:#060 1px solid;
background-color:#d2ffd2;
padding-left:3px;
padding-right:3px;
}
.paginationNumber a:link{
color:#000;
text-decoration:none;
border:#060 1px solid;
background-color:#F0F0F0;
padding-left:3px;
padding-right:3px;
}

.paginationNumber a:visited{
color:#000;
text-decoration:none;
border:#999 1px solid;
background-color:#f0f0f0;
padding-left:3px;
padding-right:3px;
}

.paginationNumber a:hover{
color:#000;
text-decoration:none;
border:#999 1px solid;
background-color:#f0f0f0;
padding-left:3px;
padding-right:3px;
}

.paginationNumber a:active{
color:#000;
text-decoration:none;
border:#999 1px solid;
background-color:#f0f0f0;
padding-left:3px;
padding-right:3px;
}
</style>



</head>




<body>





<?php
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error);
$db = mysql_select_db('directory', $conn) or die(mysql_error);


$sql = mysql_query("SELECT * FROM linkedin ORDER BY id ASC");
$nr = mysql_num_rows($sql); // get total num of rows
if (isset($_GET['pn'])) { //get pn from url vars if is is present
    $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); //filter every thing but num for security

} else {
    $pn = 1;
}

$itemsperpage = 10;

$lastpage = ceil($nr / $itemsperpage);

if ($pn < 1) { //if it is less then 1
    $pn = 1; //force it to be 1

} else
    if ($pn > $lastpage) // if it is greater then lastpage
        {

        $pn = $lastpage; //force it to be last value

    }

//this create number to click in between next and back buttons

$centerpages = ""; //initialize the veriable
$sub1 = $pn - 1;
$sub2 = $pn - 2;
$add1 = $pn + 1;
$add2 = $pn + 2;

if ($pn == 1) {
    $centerpages .= '&nbsp; <span class ="pagNumActive">' . $pn . '</span> &nbsp;';
    $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 .
        '">' . $add1 . '</a> &nbsp;';


} else
    if ($pn == $lastpage)
    {
        $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 .
            '">' . $sub2 . '</a> &nbsp;';
        $centerpages .= '&nbsp; <span class ="pagNumActive">' . $pn . '</span> &nbsp;';
    } else
        if ($pn > 2 && $pn < ($lastpage - 1))
        {
            $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 .
                '">' . $sub2 . '</a> &nbsp;';
            $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 .
                '">' . $sub1 . '</a> &nbsp;';
            $centerpages .= '&nbsp; <span class="pagNumActive"> ' . $pn . '</span> &nbsp;';
            $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 .
                '">' . $add1 . '</a> &nbsp;';
            $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 .
                '">' . $add2 . '</a> &nbsp;';
        } else if ($pn > 1 && $pn < $lastpage)
        {

                $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 .
                    '">' . $sub1 . '</a> &nbsp;';
                $centerpages .= '&nbsp; <span class="pagNumActive"> ' . $pn . '</span> &nbsp;';
                $centerpages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 .
                    '">' . $add1 . '</a> &nbsp;';


            }
// ths line set the limit 2values choese the range
//$limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
$limit = 'LIMIT ' . ($pn - 1) * $itemsperpage . ',' . $itemsperpage;

$sql2 = mysql_query("SELECT id, fname, lname, company FROM linkedin ORDER BY id ASC $limit ");
///// end adam's paging logic////


////admins paggination display setup///
$paginationDisplay = ""; //initializting pagging output veriable


if ($lastpage != "1") {
    $paginationDisplay .= 'Page <strong>' . $pn . '</strong> of  ' . $lastpage;
    //if we are not on page 1 we can place the back button
    if ($pn != 1) {
        $previous = $pn - 1;
        $paginationDisplay .= ' &nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous .
            '">Back</a>';
    }
    // lay in to clinckable number display here betweek back and next links
    $paginationDisplay .= '<span class="paginationNumber">' . $centerpages .
        '</span>';

    if ($pn != $lastpage) {
        $nextpage = $pn + 1;
        $paginationDisplay .= ' &nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextpage .
            '">Next</a>';
    }
} // end adams pagination display setup////


// build the output section here


$Outputlist = '';
while ($row = mysql_fetch_array($sql2)) {

    $id = $row['id'];
    $fname = $row['fname'];
    $lname = $row['lname'];
    $company = $row['company'];


    @$outputList .= '
<table width="100%">
                  <tr>
                    <td width="13%" rowspan="2"><div style=" height:50px; overflow:hidden;"></div></td>
                    <td width="14%" class="style7"><div align="right">Name:</div></td>
                    <td width="73%"><a href="profile.php?id=' . $id .
        '" target="_self">' . $fname . '</a> </td>
                  </tr>
                  <tr>
                    <td class="style7"><div align="right">Company:</div></td>
                    <td>' . $company . '</td>
                  </tr>
                  </table>
 <hr />';


}




?>

<div style ="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFFFFF; border:#999 solid 1px;">
<?php echo $paginationDisplay; ?>
</div>
 <table width="80%" align="center" cellpadding="6">
        <tr>
          <td><br /><br />
<?php echo $outputList; ?></td>
        </tr>
      </table>

<div style ="margin-left:58px; margin-right:58px; padding:6px; background-color:#FFFFFF; border:#999 solid 1px;">
<?php echo $paginationDisplay; ?>
</div>



</body>


</html>

Wednesday, 20 July 2016

Remove Duplicate Rows without Temporary Table

We as a developer, often come across situations where we have to work on database related stuffs. Mostly it is done when client send you its data in form of excel sheets and you push that data to database tables after some excel manipulations. I have also done it many times.
A very common problem faced in this approach is that it might result in duplicate rows at times, because data sent is mostly from departments like HR and finance where people are not well aware of data normalization techniques [:-)].
I will use Employee table where column names are id, name, department and email.
Below are the SQL scripts for generating the test data.
Create schema TestDB;

CREATE TABLE EMPLOYEE
(
    ID INT,
    NAME Varchar(100),
    DEPARTMENT INT,
    EMAIL Varchar(100)
);

INSERT INTO EMPLOYEE VALUES (1,'Anish',101,'anish@howtodoinjava.com');
INSERT INTO EMPLOYEE VALUES (2,'Lokesh',102,'lokesh@howtodoinjava.com');
INSERT INTO EMPLOYEE VALUES (3,'Rakesh',103,'rakesh@howtodoinjava.com');
INSERT INTO EMPLOYEE VALUES (4,'Yogesh',104,'yogesh@howtodoinjava.com');

--These are the duplicate rows

INSERT INTO EMPLOYEE VALUES (5,'Anish',101,'anish@howtodoinjava.com');
INSERT INTO EMPLOYEE VALUES (6,'Lokesh',102,'lokesh@howtodoinjava.com');

Solution:

DELETE e1 FROM EMPLOYEE e1, EMPLOYEE e2 WHERE e1.name = e2.name AND e1.id > e2.id;
Above sql query will delete rows where name field is duplicate and only those unique rows will be retained where name is unique and ID field is lowest. For example rows with ID 5 and 6 will be deleted and rows with 1 and 2 will be retained.
delete-duplicate-rows-in-mysql
If you want to retain rows with latest generated ID values, then reverse the condition in where clause to e1.id < e2.id like this:
DELETE e1 FROM EMPLOYEE e1, EMPLOYEE e2 WHERE e1.name = e2.name AND e1.id > e2.id;
If you want to compare multiple fields and add appropriate where clause.
Note: Please execute above (or modified) query first on test data always to make sure it is producing the expected output.
Happy Learning !!

Friday, 27 June 2014

Get Array Value in Combobox From MYSQL DataBase PHP

<?php
    @$conn = mysql_connect("localhost", "root", "");
    mysql_select_db("test", $conn);

    $query = "SELECT * from member";
    $result = mysql_query($query, $conn) or die(mysql_error());
    $num= mysql_num_rows($result);


    if ($num> 0) {
     while ($row = mysql_fetch_assoc($result)) {
        $array[] = array(
           'uid' => $row["uid"],
           'fname' => $row["fname"]
        );
     }
    }
    ?>

<form name="form" action="next.php" method="get">
        <select name="uid">
        <?php
        foreach($array as $value) {
          print("<option value=\"{$value['uid']}\">{$value['fname']}</option>");
        }
        ?>
        </select>
        <input type="submit" value="Send" />
</form>

Wednesday, 4 June 2014

Access control modifiers in php


There are a number of special keywords you can place before a class, a class function definition, or a class variable to alter the way PHP works with it - here's the full list, along with what each of them does:
  • Public: This variable or function can be used from anywhere in the script
  • Private: This variable or function can only be used by the object it is part of; it cannot be accessed elsewhere
  • Protected: This variable or function can only be used by the object it is part of, or descendents of that class
  • Final: This variable or function cannot be overridden in inherited classes
  • Abstract: This function or class cannot be used directly - you must inherit from them first
That is just a vague description of what each of them do - to make sure you fully understand each of them, here are examples:




<?php


class Example {
    public $a = 1;
    protected $b = 2;
    private $c = 3;
    
    function show_abc()
{
        echo $this -> a ;
        echo $this -> b;
        echo $this -> c;
    }
}

$example = new Example();


echo "Publc a: {$example->a}<br/>";
//echo "Protected b: {$example->b}<br/>";
//echo "Private c: {$example->c}<br/>";


$example->show_abc();



?>

understanding class inheritance

<?php

class car{
    var $wheels = 4;
    var $doors = 4;
    function wheelsdoors(){
        return $this->wheels + $this->doors;
        
    }
    
    
}


class CompactCar extends car{
    
    var $doors = 2;
        
}

$car1 = new car();
$car2 = new CompactCar();


echo $car1->wheels . "<br>";
echo $car1->doors . "<br>";
echo $car1->wheelsdoors(). "<br>";
echo  "<br>";
echo  "<br>";
echo  "<br>";


echo $car2->wheels . "<br>";
echo $car2->doors . "<br>";
echo $car2->wheelsdoors(). "<br>";




?>

Monday, 26 May 2014

Passing PHP form variables from one page to other pages

 File:form.php

<form method="post" action="form2.php">
    <input type="text" name="name">
    <input type="text" name="email_address">
    <input type="submit" value="Go To Step 2">
</form>







<?php

//let's start the session  File:form2.php
session_start();

//now, let's register our session variables
 $name = $_SESSION['name'];
$email = $_SESSION['email_address'];


//finally, let's store our posted values in the session variables
$_SESSION['name'] = $_POST['name'];
$_SESSION['email_address'] = $_POST['email_address'];

?>
<form method="post" action="form3.php">
<input type="radio" name="membership_type" value="Free">
<input type="radio" name="membership_type" value="Normal">
<input type="radio" name="membership_type" value="Deluxe">
<input type="checkbox" name="terms_and_conditions">
<input type="submit" value="Go To Step 3">
</form>




<?php

//let's start the session  File:form3.php
session_start();

//now, let's register our session variables

$membership_type = $_SESSION['membership_type'];
$terms_and_conditions = $_SESSION['terms_and_conditions'];
//session_register('membership_type');
//session_register('terms_and_conditions');

//finally, let's store our posted values in the session variables
$_SESSION['membership_type'] = $_POST['membership_type'];
$_SESSION['terms_and_conditions'] = $_POST['terms_and_conditions'];

?>
<form method="post" action="form_process.php">
<input type="text" name="name_on_card">
<input type="text" name="credit_card_number">
<input type="text" name="credit_card_expiration_date">
<input type="submit" value="Finish">
</form>




<?php
 //form_process.php
//let's start our session, so we have access to stored data
    session_start();
   
    $_SESSION['name_on_card'] = $_POST['name_on_card'];
     $_SESSION['credit_card_number'] = $_POST['credit_card_number'];
      $_SESSION['credit_card_expiration_date'] = $_POST['credit_card_expiration_date'];
   
   

 echo $name = $_SESSION['name'];
 echo $email = $_SESSION['email_address'];
echo $membership_type = $_SESSION['membership_type'];
echo $terms_and_conditions = $_SESSION['terms_and_conditions'];


 echo $name_on_card = $_SESSION['name_on_card'];
echo $credit_card_number = $_SESSION['credit_card_number'];
echo $credit_card_expiration_date = $_SESSION['credit_card_expiration_date'];

 ?>

Friday, 23 May 2014

Taskfeed Project Management Software - CodeCanyon



Download















IMPORTANT!!!

Taskfeed PE v1.45 now available! Supports UTF 8 / Unicode application wide! Please upgrade now

What is TASKFEED?

Taskfeed is a Project Management Software built upon ideas and experiences from real life project cycle and interactions. Over the years I’ve used many Project Management tools. While many of them served the purpose right, I found them bloated or overly complicated at times.
I realized that, Task/Project Management software can do a world of good if there was a Team Environment. A way to keep it simple, clean and elegant. Taskfeed is meant for TeamWork. Create your team and manage your projects together! Get notified on the go and have fun organizing your ever so cluttered project queue.
Taskfeed Currently features (but is not limited to)
  • Responsive UI
  • Invitation to join Taskfeed/Your Project by email.
  • Creating your own team to work with.
  • Apps for To-Do, Milestones and Discussion.
  • Attachment in discussion.
  • Threaded Discussion View.
  • Email Notification for all major events on a project.
  • Runs on simple Apache Server
  • User Roles as Project Owner and Contractors.
  • Managing your priority Queue
  • Task Calendar.
  • Public 3D Business Card!
  • Task and Project Management Panels.

Manage Your Team!


Create and manage your team easily with TaskFeed! Just type in the email address or username of the person you want in your team and hit ENTER! If the user is already in Taskfeed, he’ll get notified immediately, if he’s not, the system will send an invitation to the email address and request him/her to join TAKSFEED. In Taskfeed or not, after registration and logging in, there will be the notification waiting and reminding the user to join your team!

Dashboard


The TASKFEED dashboard is your hub to link up all the happenings at Taskfeed that you care. You can jump onto all the discussions ToDo and milestones directly from the Dashboard links. You can view the Task Calendar too. All the actions of Taskfeed can be accessed from the colorful buttons on the right side bar.

Manage Your Task


Shows you all the projects you are currently working on. Quickly access and browse through your current projects or take required actions. You may leave any project from this window when and if you need to.

Manage Your Projects


As the title says, it lets you manage all your projects. You can view, jump to discussion or remove a project from here.

Discussion APP


Inside every project, you can install the DISCUSSION App. Helps you keep connected with the contractors and discuss about whats going on or what needs to be done. You and the other parties can attach files and screenshots and whatever needed to assist the progress of the project.

Simple Stock Manager - codecanyon



DEMO











Summary codecanyonsimple

EmployeeBook is a simple CodeIgniter based system that helps organizations manage employees. It can be used by all organizations. Some of the main features are user management, task management, role management and leave management.

Demo Credentials


Admin Login: Demo URL : http://codeigniterforms.com/EmployeeBook
Admin Username: admin
Admin Password: password

Employee login:
Employee Username: employee
Employee Password: password


Supervisor login:
Supervisor Username: demo
Supervisor Password: password
The above accounts shouldn’t be edited. All data entered will be removed in a day or two.

What is this

EmployeeBook is an efficient employee management system for organisations. Using this system you can easily manage your employees.

Following are the main modules :
  1. User Manager : Provides user management functionality with ACL.
  2. Leave Manager : Provides leave management functionality with approve/reject feature.
  3. Task Manager : Handles the daily task of employees.
  4. Role Manager : Deals with the user levels.

Why this

It is very easy to use and has the following features :
  • 100% Responsive and works in all platforms(Mobile, Tablets & Desktops).
  • Email notifications.
  • Export leave to CSV.
  • Allot leave and leave balance feature.
  • Apply for Team leave functionality.
  • Approve/reject team leave functionality.
  • Powerful ACL.
  • Simple Interface.
  • Apply for leave functionality.
  • Leave can be applied for Full day or half day(First half or second half)
  • Approve/Reject/Cancel Leave functionality.
  • Add/Edit task functionality.
  • Leave listing with advanced filters.
  • Task listing with edit task functionality.
  • Standalone based on codeigniter

Get Started

There is an automated installation process which will install the setup at your server or your local environment. You need to just copy and paste the contents of the folder “EmployeeBook” at your hosting.
This installation process will install all the necessary files and database.

  • Next you can add your employees from the “Add Employee” section and assign their role “Employee”.
  • Provide your employees with their username and password.
  • Now your employees can login from the login panel and perform their tasks.
  • Employees can add their daily tasks as well as edit the details of the added
    task.
  • Employee can apply for a leave from the “Apply Leave” section.
  • Those added tasks and leaves can be viewed from the “Task list” and the “All leave listing” sections.
  • Hence you can manage the progress as well as the leaves of your employees.
  • You can also maintain a healthy competitive environment from the “Recent Updates” section.

Leave Manager

Leave management plays an important role in any successful organisation to work efficiently.
EmployeeBook provides an efficient leave management interface to the organisation where employees can apply for a leave and the HR can take necessary action on the applied leave (Approve, Reject or cancel) and the employee can view the status of the applied leave instantly.

Apply Leave
Here the employee can apply for a leave by selecting the type of leave(Annual, medical..) date and submit it to the HR for review.

Apply Team Leave
Here the supervisor can apply for leave on behalf of team member.

Email notifications
  • Email notifications are sent to the Supervisor when a leave is applied.
  • When the supervisor Approves or Rejects a leave the the employee is sent an email regarding approval or rejection.
Allot leave and leave balance feature
  • Leave need to be allotted to the employee based on the leave types. Like 20 Annual leave alloted to some demo employee..
  • Leave record is maintained for each and every employee.
  • IMPORTANT: For an employee to apply for a leave, leave have to allotted by admin or supervisor first.
  • When an employee apply for a leave then leave is deducted from that particular leave type. like if an employee has 18 Annual leaves and applies for 2 annual leave then the leave balance will be: 16
Team Feature
By this feature we can maintain individual functional groups
  • In this feature the Supervisors can view their team members leave.
  • They can take necessary actions such as Approve team members leave, reject team members leave based on permissions.
  • Supervisor can also apply for a leave on behalf of team member.
My Leave List
Here the employee can see the applied leaves and their status

Leave Listing
This section is restricted for the HR and Admin. Here the HR gets a listing of leaves submitted by all the employees of the organisation and can take necessary action.

Task Manager

Task manager provides an interface to the employees of the organisation for maintaining their daily tasks.They can add their daily task and at the end of the day they can edit the status of the task.
The Admnistrator of the organisation can see a listing of the task added by all the employees and can trace the work progress.

Add Task
Here the employees can add their task by writing the title description of the task with the estimated time.

My Task List
Here the employees can see their task listing and take the required action on their task.

Edit Task
Here the employee can change the status of the selected task.

Task List
Here the admin can see the task of all the employees and trace the work done.

User Manager

This section is restricted to the Administrator for managing the employees and their details.
Here the administrator can add a new employee, see a listing of all the employees
and edit the details of any employee.
From the employee listing the admin can activate/deactivate any employee and go to the edit section for editing employee details.

Add Employee
Admin can add a new employee from this panel by providing a username, password, email, date of joining, role and supervisor.

User List
Here you can see a listing of all the employees and perform various actions such as edit particulars of the selected employee, activate/deactivate the employee and delete a particular employee.

Edit Employee
Here you can edit the particulars of any employee and change the details of the selected employee.

Activate/Deactivate
Here you can deactivate a particular employee and that employee will not be able to login.

Delete Employee
Here you can delete the employee.

Role Manager

In an organisation we have different levels such as Employee, HR, Manager, Admin etc. We can call these as categories within which we can distribute our organisation and every user level has its own work.
We can categories our work and create as many roles as we want from the create new role panel.
After creating new role we will have to decide their capabilities and assign permissions to them.

Add New Role
Here you can add a new role by providing name and description of the role eg role can be HR and description Human Resource Department

Role Listing
Here you have the listing of all the roles in the organisation and you can perform various operations on those roles such as view, edit and permissions

Edit Role
Here you can edit the role name and description.

Permission
Here you can provide module wise permissions to the selected role. By providing permissions theemployee falling underthose rolescan access those modules.











Donwload Link