如何添加,编辑和删除数据库的逗号分隔值。 [英] how to add , edit and delete comma separated value of database .?

查看:223
本文介绍了如何添加,编辑和删除数据库的逗号分隔值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个称为角色的表,字段类似(roleid,role,prohibitedprocess,prohibitedports),这里roleid是唯一的。和我有一个逗号分隔的值为prohibitprocess字段(例如:prohibitprocess ---> skype,teamviwer,记事本)。

i have created one table called role and the fields are like (roleid,role,prohibitedprocess,prohibitedports) here roleid is unique. and i have a comma separated value for "prohibitedprocess" field .(ex: prohibitedprocess---> skype,teamviwer,notepad).

问题是如何添加和编辑和删除禁用过程的逗号分隔值。是否可能?

the problem is how to add and edit and delete that comma separated value of prohibitedprocess .is it possible ?

我已经从数据库获取代码.code是

i have fetch the code form the data base .code is

      <?php 
                $sql = "SELECT roleid, prohibitedprocess, prohibitedports FROM role WHERE role='Basic'";
                $option='';
                $result = mysql_query($sql);
                while($row = mysql_fetch_assoc($result))
                {
                    $pro_proc = $row['prohibitedprocess'];
                    $lst = explode(",",$pro_proc);
                                        //Print in Option Box
                    foreach($lst as $exp)
                    {?> 
                        <tr>            
                        <td><?php echo $exp;?></td>
                        <td><a href="edit_form.php?id=$row[roleid]">Edit</a></td>
                        <td><a href="del_form.php?id=$row[roleid]">Delete</a></td></tr>
            <?php   
                    }
                }                       
                ?>

如何做到这一点请帮助我

How to do this please help me

推荐答案

您可以编辑整个字符串。 。

You can edit the whole string . .

我只是使用str_replace函数

I mean just using str_replace function

例如

$string = "skype,teamviwer,notepad";

$old_value = "skype";

$new_value = "facebook";

$new_string = str_replace($old_value,$new_value,$string);

然后只需将此新字符串更新到数据库表。 。

Then simply update this new string into database table. .

这篇关于如何添加,编辑和删除数据库的逗号分隔值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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