how to add , edit and delete comma separated value of database .?

后端 未结 3 931
忘掉有多难
忘掉有多难 2021-01-14 11:42

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 \"

相关标签:
3条回答
  • 2021-01-14 12:19

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

    0 讨论(0)
  • 2021-01-14 12:21

    One way would be to retrieve all of 'keywords' in an input element and edit them like a sentence. However, for what you want to do, you may wanna add a new table called prohibitedprocess and use roleid as a foreign key. Then retrieve from that table according the roleid. eg: SELECT item FROM prohibitedprocess p, role r WHERE p.roleid = r.roleid

    0 讨论(0)
  • 2021-01-14 12:21

    It may be better to make another table for that relation, then you could edit it normally. Otherwise you can take your comma separated list and do something in javascript.

    var commaSeparatedList = <?php echo $commaSeparatedList;?>
    var realData = commaSeparatedList.split(',');
    // when the user adds something you can add to the array or delete 
    // from the array
    var newCommaList = readData.join([separator = ',']);
    // some kind of get/post request that sends the new comma list
    
    <?php
        $newList = GET_REQUEST_PARAMS["newCommaList"];
        // sql update query that updates the comma list
    ?>
    

    I haven't used php in a while so I know GET_REQUEST_PARAMS isn't a thing but i'm sure you know how to get the parameters.

    Or without javascript you can use a form that posts back all the names of prohibited things

    <?php 
        $newList = ""
        //foreach through the get params which contain the names
        foreach()
        {
            $newList += getParam + ",";
        }
        // some code to remove that last comma
        // sql update 
    ?>
    
    0 讨论(0)
提交回复
热议问题