Construction process with Php+ajax (leave, arrival, shipment, etc.)

Source: Internet
Author: User
This article mainly introduces the new process with Php+ajax (leave, arrival, shipment, etc.), the need for friends can refer to the following

For the manager, the computer operation of the leave process is much more efficient than the manual leave process, so how to create a new process?

First: What processes do you need to be clear?

Second: Does each process need those people to execute?

Finally: What is the order of the people executing the process?

The first step: three tables are required, namely: User table; Liucheng table; Liuchengjiedian table (the next two have not been added)

Step Two: Read the contents of the Users table with a drop-down list:

<p id= "Top" ><p> Please select node personnel: </p><select id= "User" ><?phprequire ". /db.class.php "; $db = new DB (); $sql =" SELECT * from users "; $arr = $db->query ($sql); foreach ($arr as $v) {echo" <opti On value= ' {$v [0]} ' >{$v [2]}</option> ";}? ></select><input type= "button" value= "OK Add"/></p>

Implementation results:

Step three: Click "OK to add" to add the selected person to the session

(1) First introduce the jquery package

<script src= ". /jquery-1.11.2.min.js "></script>

(2) Ajax code

<script type= "Text/javascript" >//Session Access Select a value of $ ("#add"). Click (function () {   var uid = $ ("#user"). Val ();  alert (UID);   $.ajax ({    URL: "add-cl.php",    data:{uid:uid},    type: "POST",    dataType: "TEXT",    success:function ( Data) {     window.location.href= "main.php" rel= "external nofollow" rel= "external nofollow";    }   );   }) </script>

(3) add-cl.php page

<?php//Open session session_start (); Value $uid =$_post["UID"]; If the SESSION is empty, make an array, add the values taken to the if (Empty ($_session["Jiedian"])) {  $arr = array ($uid);  $_session["Jiedian"] = $arr; }//If it is not empty, append the fetch value to the else {  $arr = $_session["Jiedian"];  $arr []= $uid;  $_session["Jiedian"] = $arr; }?>

Fourth Step: List the selected people

(1) First determine if the value of the session is taken

<?php    session_start ();     if (Empty ($_session["Jiedian"])) {      echo "has not yet selected a node person! ";    }

(2) After the session is taken

else    {     $arr = $_session["Jiedian"];     foreach ($arr as $k = + $v)     {      $sql = "Select name from users where uid= ' {$v} '";      $name = $db->strquery ($sql);      echo "<p>{$k}--{$name}--<input type = ' button ' value= ' Remove ' class= ' Yichu ' code= ' {$k} ' > <p> ';     }         }       ?>


(3) Add a click event to the "Remove" button

Ajax page:

$ (". Yichu"). Click (function () {  var code = $ (This). attr ("code");  $.ajax ({    URL: "yichu-cl.php",    Data:{code:code},    type: "POST",    dataType: "TEXT",    success: function (data) {     window.location.href= "main.php" rel= "external nofollow" rel= "external nofollow";    }   });   })

yichu-cl.php page:

<?phpsession_start (); $code = $_post["code"]; $arr = $_session["Jiedian"];//remove code from the array unset ($arr [$code]);// Rearrange indexes $arr = array_values ($arr); $_session["Jiedian"] = $arr;? >

Click Remove Harry: Zhang San and Saturday are remaining, and code is rearranged

Last step: Add a Save button to add data to the database

Note: All data before this is present in the session

(1) Add Process name input box and save button

<p id= "BTM" >    Please enter the process name:   <input type= "text" class= "name"/>   <input type= "button" value= "Save" class= "Baocun"/>   </p>

(2) Click the Save button to store all the information in the database

Ajax Code

$ (". Baocun"). Click (function () {  var name = $ (". Name"). Val ();//  alert (name);  $.ajax ({    URL: "baocun-cl.php",    data:{name:name},    type: "POST",    dataType: "TEXT",    success: function (data) {     alert ("Saved successfully! ");    }   });  })

baocun-cl.php page

<?phpsession_start (); Require ". /db.class.php "; $db = new DB ();//writes data into Liucheng table $name = $_post[" name "]; $code =time ();//timestamp to generate Code$sql =" INSERT INTO Liucheng values (' {$code} ', ' {$name} '), $db->query ($sql, 0);//Writes data to Liucehngjiedian table $arr = $_session["Jiedian"]; foreach ($arr as $k = + $v) {$sql = "insert into Liuchengjiedian values (', ' {$code} ', ' {$v} ', ' {$k} ')"; $db->query ($sql , 0);}? >

To implement the effect and write data to the database:

To this step will be able to achieve the whole of Liu New process steps, the later can be the interface to beautify a little ~ ~ ~

Summary: Each step of the processing page is more important; sessoin access data; unsettle () move the divisor group; Array_values () rearrange the array, etc. ~ ~ ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.