简体   繁体   中英

post.php X-Editable save data to MYSQL database

what code should be written to the post.php, that information is stored in the database but just is recorded only is array

<a data-original-title="access" data-pk="1" data-type="checklist" data-value="" id="access"></a>


    $(".editable-form #access").editable({
      source: [
     {value: 1,text: "a"},
     {value: 2,text: "b"},
     {value: 3,text: "c"},
     {value: 4,text: "d"},
     {value: 5,text: "f"}
      ],
        url:"post.php",
        name: "access"
    });


post.php

        if($_POST['name']=='access'){
            $pk = $_POST['pk'];
            $value=$_POST['value'];

              //when i do echo $value result type array 

              //but i want just value = { 0: "1", 1: "2", 2: "3", 3: "4" }

     $result = mysqli_query($mysqli,"UPDATE `books` SET `access`='$value' WHERE `id`='$pk'");   
          }

Use this

json_encode(array(1, 2, 3, 4), JSON_FORCE_OBJECT);

returns

{"0":1,"1":2,"2":3,"3":4}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM