编辑内爆字符串 [英] Editing an imploded string

查看:191
本文介绍了编辑内爆字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以分配任务,如清洗浴室,洗车等。我可以分配一个任务让我们说3到4人使用下面的代码

  if(isset($ _ POST [btnassign])){
$ proj = $ _REQUEST ['projhid'];
$ analyst = $ _POST ['analyst'];
$ commaList = implode('|',$ analyst);
$ queupass =UPDATE projects set assignedto ='$ commaList',assignedby ='$ uname'where projectname ='$ proj';
$ queresupass = odbc_exec($ conn,$ queupass);
$ notifassign =新建项目;
$ queprojgn =INSERT INTO通知(通知,日期时间,isread,createdby,createddate)
values('$ notifassign',GETDATE(),0,'$ uname',GETDATE());
$ queprojresnot = odbc_exec($ conn,$ queprojgn);
echo< script type ='text / javascript'>;
echowindow.close();;
echo< / script>;

上面的代码是分配的一部分,因为我可以将一个任务分配给多个工作人员使用他们的ID。

现在,我还有一个锚标记,它将显示分配给该项目的工作人员,如下面的分析人员所说:ANALYST





如果我点击那个锚标签,我想要得到分析师列表分配给这个任务,但是请记住,使用他们的ID分配的工人内部爆炸像\\ b
$ b

1 | 2 | 3 | 4 | 5



我有下面这个代码爆炸它

$ $ p $ $ que =SELECT assignedto FROM PROJECTS where projectname ='$ projname';
$ queres = odbc_exec($ conn,$ que);
$ res = odbc_result($ queres,1);
$ analyst = explode(|,$ res);
echo $ analyst [0]; // piece1
echo $ analyst [1]; // piece2
echo $ analyst [2]; // piece1
echo $ analyst [3]; // piece2
echo $ analyst [4]; // piece1
echo $ analyst [5]; // piece2
echo $ analyst [6]; // piece1
echo $ analyst [7]; // piece2
die();

这是最后的工作,但我需要的是爆炸它一个地方它有一个删除锚标签,如下所示,任何帮助将不胜感激。


<这可以通过以下方式实现:


  1. 选择< code $ c> assignto 从这样的表中获得



    $ que =SELECT assignedto FROM PROJECTS where projectname = '$ projname';


  2. 爆炸收到的字符串:

    $ analyst = explode(|,$ res);

  3. 使用 array_diff 去除所需的工作人员:



    $ new_analysts = array_diff($ analyst,$ remove_wo


  4. 将新数组拼接到一个分隔符的字符串:
    = implode(| ,$ new_analysts);


编辑:

使用remove链接创建HTML表格

  $ que =SELECT assignedto FROM PROJECTS where projectname ='$ projname'; 
$ queres = odbc_exec($ conn,$ que);
$ res = odbc_result($ queres,1);
$ analyst_arr = explode( ,$ res);

$ analyst = implode(,,$ analyst_arr);

$ que2 =SELECT [user_id,first name,last name] FROM [用户表]其中[user_id] IN'$ analytical';
$ query = odbc_exec($ conn,$ que2);
$ result = odbc_result_all($ query);

foreach($ result as $ val){
$ user_id = $ val ['user_id'];
$ users [$ user_id] = $ val;
}

在此之后,您只需循环 $ analyst_arr 并创建表所需的HTML。



希望这可以帮助。



干杯!


I have an application in which I can assign task like cleaning the bathroom, washing the car and etc. I can assign a single task to let's say 3 to 4 persons using the code below

if (isset($_POST["btnassign"])){
$proj = $_REQUEST['projhid'];
$analyst = $_POST['analyst'];
$commaList = implode('| ', $analyst);
$queupass = "UPDATE projects set assignedto='$commaList', assignedby = '$uname' where projectname='$proj'";
$queresupass = odbc_exec($conn,$queupass);
$notifassign = "New Project Assignment";
$queprojgn = "INSERT INTO notification (notification,datetime,isread,createdby,createddate) 
                       values('$notifassign',GETDATE(),0,'$uname',GETDATE())";
$queprojresnot = odbc_exec($conn,$queprojgn);
echo  "<script type='text/javascript'>";
echo "window.close();";
echo "</script>";

The code above is the assigning part which works great since I can assign a single task to number of workers using their ID.

Now, I also have an anchor tag which will show the workers assigned for that project like the one below which says ANALYST

If I click that anchor tag, I want to get the list of analyst assigned for that task, but remember that the assigned workers using their ID are imploded like to

1| 2| 3| 4| 5

I have this code below which explodes it

$que = "SELECT assignedto FROM PROJECTS where projectname = '$projname'";
$queres = odbc_exec($conn,$que);
$res = odbc_result($queres, 1);
$analysts = explode("| ", $res);
echo $analysts[0]; // piece1
echo $analysts[1]; // piece2
echo $analysts[2]; // piece1
echo $analysts[3]; // piece2
echo $analysts[4]; // piece1
echo $analysts[5]; // piece2
echo $analysts[6]; // piece1
echo $analysts[7]; // piece2
die();

which is eventually works but what I need is to explode it an place it in table that has a remove anchor tag like the one below, any help will be highly appreciated.

解决方案

This can be achieved by:

  1. Selecting the assignedto from the table like this

    $que = "SELECT assignedto FROM PROJECTS where projectname = '$projname'";

  2. Exploding the string received:

    $analysts = explode("| ", $res);

  3. Using array_diff to get the remove the desired worker:

    $new_analysts = array_diff($analysts, $remove_worker_id);

  4. Imploding the new array to a pipe seperated string: $result = implode("| ", $new_analysts);

EDIT:

For creating the HTML table with the remove link,

$que = "SELECT assignedto FROM PROJECTS where projectname = '$projname'";
$queres = odbc_exec($conn,$que);
$res = odbc_result($queres, 1);
$analysts_arr = explode("| ", $res);

$analysts = implode(",", $analysts_arr);

$que2 = "SELECT [user_id, first name, last name] FROM [user table] where [user_id] IN '$analysts'";
$query = odbc_exec($conn,$que2);
$result = odbc_result_all($query);

foreach($result as $val){
   $user_id = $val['user_id'];
   $users[$user_id] = $val;
}

After this, all you have to do is iterate the $analysts_arr and create the HTML needed for the table.

Hope this helps.

Cheers!

这篇关于编辑内爆字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆