Home >Backend Development >PHP Tutorial >php-process management (php+Ajax)

php-process management (php+Ajax)

大家讲道理
大家讲道理Original
2017-05-28 09:51:051721browse

php+AJAX new process

1: Need to clarify which processes need to be operated?

2: What personnel are needed to execute each process?

3: What is the order of people performing this process?

1. The three tables required for database construction are: users table; liucheng table; flowpath table (the data has been displayed in the table)

2. Create a new process page

(1) Use Drop-down listDisplays the list of people and adds an add button


<h1>新建流程</h1>
<p>
请选择节点人员:
	<select id="user">
    <?php
	session_start();
	require"../DBDA.class.php";
	$db = new DBDA();
	$sql = "select * from users";
	$arr = $db->query($sql,1);
	foreach($arr as $v)
	{
		echo"<option value=&#39;{$v[0]}&#39;>{$v[2]}</option>";  //输出单选按钮,数组中的索引2,也就是用户名,但是它的值是代号
	}
	?>
    </select>
    
<input type="button" value="添加节点" id="addjd" />
</p>
<br />


(2) Add a click event to the Add Node button

##

$("#addjd").click(function(){
		var uid = $("#user").val();
		$.ajax({
				url:"add.php",
				data:{uid:uid},
				type:"POST",
				dataType:"TEXT",
				success: function(data){
						window.location.href="xinjian.php";//执行处理页面成功后会刷新页面
					}
			}) 
	})


(3) Add a node The processing page add.php

<?php
session_start();
$uid = $_POST["uid"]; //接收传过来的值if(empty($_SESSION["jiedian"]))
{
	$arr = array($uid);//定义一个数组放用户
	$_SESSION["jiedian"] = $arr; //将第一个用户放入数组中}
else
{
	$arr = $_SESSION["jiedian"];//数组中有值
	$arr[] = $uid; //放入数组中值
	$_SESSION["jiedian"] = $arr; //将值再交给session}


(4) Display the added node

# in the new process page

##
<p>
<?php
if(empty($_SESSION["jiedian"]))
{
	echo"还未添加节点人员!";
}
else
{
	$arr = $_SESSION["jiedian"];
	foreach($arr as $k=>$v)
	{
		$sql ="select name from users where uid=&#39;{$v}&#39;";
		$name =$db->strquery($sql);
		echo"<p>{$k}--{$name}--<input type=&#39;button&#39; value=&#39;移除&#39; class=&#39;yichu&#39; sy=&#39;{$k}&#39;/></p>";
	}
}
?>
</p>
<br />


After completing this step, the effect is as follows:

(5) Add the remove button Click event

$(".yichu").click(function(){
		var sy = $(this).attr("sy"); //点击这个按钮,选中这个的索引号
		$.ajax({
			url:"yichu.php",
			data:{sy:sy},
			type:"POST",
			dataType:"TEXT",
			success: function(data){
				window.location.href="xinjian.php";//执行处理页面成功后会刷新页面
			}
		});
	})


(6) Remove the processing page yichu.php

<?php
session_start();

$sy =$_POST["sy"]; //接收穿过来的索引号$arr = $_SESSION["jiedian"];//节点的数组unset($arr[$sy]); //删除数据$arr = array_values($arr);//重新索引$_SESSION["jiedian"] = $arr;


(7) After the node problem is solved, then there is the name of the process. The text box for writing the name: The important thing is to save the process, so there must be a save button.

<p>
请输入流程名称:<input type="text" id="mingcheng" />
</p>
<br />
<input type="button" value="保存" id="baocun" />



(8) Add a click event to the save button

$("#baocun").click(function(){
	var name = $("#mingcheng").val();
	$.ajax({
		url:"baocun.php",
		data:{name:name},
		type:"POST",
		dataType:"TEXT",
		success: function(data){
			alert("保存成功!");
		}
	});
})	


(9) Finally, there is the processing page to save the process

<?php
session_start();
require "../DBDA.class.php";
$db = new DBDA();

$name = $_POST["name"];
$code = time();

$sql ="insert into liucheng values(&#39;{$code}&#39;,&#39;{$name}&#39;)";
$db->query($sql);

$arr = $_SESSION["jiedian"];

foreach($arr as $k=>$v)
{
	$sql ="insert into flowpath values(&#39;&#39;,&#39;{$code}&#39;,&#39;{$v}&#39;,{$k})"; //注意建表的类型,这里的orders项用的是int型,所以{$k}不用加&#39;&#39;,而且建表主键要勾选自增长
	$db->query($sql);
}



##Of course, the content is also stored in the database accordingly. The effect can be seen in the top data table

The following code is used for

copy

:

1.xinjian.php

##
b585974ae3b7dba3039af53a9593f9c4
383eb734b02b508089ba2d78eb4c6f68
93f0f5c25f18dab9d176bd4f6de5d30e
0f3eabac747cdf61a51589c5584ae6e8
b2386ffb911b14667cb8f0f91ea547a7无标题文档6e916e0f7d1e588d4f442bf645aedb2f202954c7e92b91561876db61cd5335d82cacc6d41bbb37262a98f745aa00fbf09c3bca370b5104690d9ef395f2c5f8d1

6c04bd5ca3fcae76e30b72ad730ca86d
4a249f0d628e2318394fd9b75b4636b1新建流程473f0a7621bec819994bb5020d29372a
e388a4556c0f65e1904146cc1a846bee请选择节点人员:    49821feaa8adcef869675df18bcd0aad
    02c3585e263069ccf55a7ec27c12db82query($sql,1);    foreach($arr as $v)
    {        echo"8dfcd5164ba7c14d3a3a5df4cc194797{$v[2]}4afa15d3069109ac30911f04c56f3338";
    }    ?>
    18bb6ffaf0152bbe49cd8a3620346341
    
41970b5e738a2bdeb6bd0b93e8a3f3bd
94b3e26ee717c64999d7867364b1b4a3
ff9d32c555bb1d9133a29eb4371c1213
e388a4556c0f65e1904146cc1a846bee
27d30a292e6e169a45a46c02f1bea765$v)
    {        $sql ="select name from users where uid='{$v}'";        $name =$db->strquery($sql);        echo"e388a4556c0f65e1904146cc1a846bee{$k}--{$name}--d94811dbc25891e95c80dc21398ddea594b3e26ee717c64999d7867364b1b4a3";
    }
}?>
94b3e26ee717c64999d7867364b1b4a3
ff9d32c555bb1d9133a29eb4371c1213
e388a4556c0f65e1904146cc1a846bee请输入流程名称:e40a0d088a545ab211475e67dfc03b96
94b3e26ee717c64999d7867364b1b4a3
ff9d32c555bb1d9133a29eb4371c1213
87df0f69fa5923d851c5500cf9c43562

36cc49f0c466276486e50c850b7e4956

8019067d09615e43c7904885b5246f0a$("#addjd").click(function(){        var uid = $("#user").val();
        $.ajax({
                url:"add.php",
                data:{uid:uid},
                type:"POST",
                dataType:"TEXT",
                success: function(data){
                        window.location.href="xinjian.php";
                    }
            }) 
    })

$(".yichu").click(function(){        var sy = $(this).attr("sy");
        $.ajax({
            url:"yichu.php",
            data:{sy:sy},
            type:"POST",
            dataType:"TEXT",
            success: function(data){
                window.location.href="xinjian.php";
            }
        });
    })
    
$("#baocun").click(function(){    var name = $("#mingcheng").val();
    $.ajax({
        url:"baocun.php",
        data:{name:name},
        type:"POST",
        dataType:"TEXT",
        success: function(data){
            alert("保存成功!");
        }
    });
})    
2cacc6d41bbb37262a98f745aa00fbf0
73a6ac4ed44ffec12cee46588e518a5e


2.add.php


db66afd0189a8d34923c7df7dad072dequery($sql);$arr = $_SESSION["jiedian"];foreach($arr as $k=>$v)
{    $sql ="insert into flowpath values('','{$code}','{$v}',{$k})";    $db->query($sql);
}


//输出单选按钮,数组中的索引2,也就是用户名,但是它的值是代号

The above is the detailed content of php-process management (php+Ajax). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn