donglu3184 2015-02-21 06:45
浏览 29
已采纳

如何添加,编辑和删除数据库的逗号分隔值。

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 ?

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   
                    }
                }                       
                ?>

Design

How to do this please help me

  • 写回答

3条回答 默认 最新

  • dongqiao1151 2015-02-21 07:01
    关注

    You can edit the whole string . .

    I mean just using str_replace function

    e.g

    $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. .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?