如何将JSON传递给复选框

如何将JSON传递给复选框

本文介绍了如何将JSON传递给复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Json

  {segment:IV级学费,VI-VIII级学费
, Board:[cbse]
,Class IV:[Allsubject]
,Class VI-VIII:[cbse,cse / Ise]
,Class VI-VIII Subject:[Allsubject,Science]
,Class XI-X:null
,Class XI-X Subject:null
, Class XI-XII:null
,Class XI-XII Subject:null
,Languagesubject:null
,engineering:null
, :null
,Dancesubject:null
,Degree Course:null
,Degree Subject:null
}

这里的键: Board
value:cbse
key:Class IV
value:Allsubject like wise json pattern in classconducted column

我的问题是:


  1. 如何检索json字符串?

  2. 我试过这样。

      $ sqledit = mysql_query(select * from tinfo where tsname = '。$ _ SESSION ['tutorname']。'); 
    $ row = mysql_fetch_array($ sqledit);
    foreach($ key => $ val){
    if($ key!=''&& $ val!='' ){
    echo'< span class =details>'。$ key。'< / span>'。':'。< br />< br />;
    if(is_array($ val))
    echo implode(',',$ val)。 <峰; br /><峰; br /> 中;
    else
    echo $ val。 <峰; br /> 中;


    code $


    现在我想编辑页面。所以使用 foreach 我分开这些值。这里我解码了json值。现在价值即将到来。我想知道如何将json值传递给我的表单。这是我的表格。我已经试过了,我不知道我的代码有什么问题。

    我想要这样做:检查这是这个正确

     < input type =checkboxname =board []value =cbse<?php if ($ val [0] =='cbse'){echochecked;}?>> CBSE 
    < input type =checkboxname =board []value =cse / Ise <?php if($ val [1] =='ICSE / ISE'){echochecked;}?>>> ICSE / ISE。


    解决方案

    你的行为与,但解析JSON而不是爆炸它是。

      $ cats = json_decode($ row ['classconducted'],true); 

    < input type =checkboxname =segment []value =Class IV Tuition<?php if(in_array('Class IV Tuition',$ cats)){echo 检查; }>?> I-V类学费


    Json

    {"segment":"Class I-V Tuition,Class VI-VIII Tuition"
     ,"Board":["cbse"]
     ,"Class I-V":["Allsubject"]
     ,"Class VI-VIII":["cbse","cse/Ise"]
     ,"Class VI-VIII Subject":["Allsubject","Science"]
     ,"Class XI-X":null
     ,"Class XI-X Subject":null
     ,"Class XI-XII":null
     ,"Class XI-XII Subject":null
     ,"Languagesubject":null
     ,"engineering":null
     ,"Diploma":null
     ,"Dancesubject":null
     ,"Degree Course":null
     ,"Degree Subject":null
    }
    
    Here  key:Board
          value:cbse
          key:Class I-V
          value:Allsubject like wise json pattern stored in classconducted column
    

    My questions are:

    1. How to retrieve the json string?
    2. I have tried like this.

      $sqledit = mysql_query("select * from  tinfo where tsname='" .$_SESSION['tutorname'] ."'");
      $row = mysql_fetch_array($sqledit);
      foreach (json_decode($row['classconducted'], true) as $key => $val) {
         if($key!='' && $val!='') {
            echo '<span class="details">'.$key.'</span>'.': '."<br/><br/>";
            if (is_array($val))
              echo implode(',', $val) . "<br/><br/>";
            else
              echo $val . "<br/>";
          }
      }
      

    Now I want to edit the page. So using foreach I separate the values. Here I have decode the json values. now the values are coming . I want to know how to pass the json values to my form. Here is my form. I have tried like this, I don't know what is wrong in my code.

    I want ouptut like this: check this is this correct

    <input type="checkbox" name="board[]"  value="cbse" <?php if($val[0]=='cbse'){echo "checked";}?>>CBSE
    <input type="checkbox" name="board[]"  value="cse/Ise" <?php if($val[1]=='ICSE/ISE'){echo "checked";}?>>ICSE/ISE.
    
    解决方案

    You do the same as in your other question, but parse the JSON instead of exploding it.

    $cats = json_decode($row['classconducted'], true);
    
    <input type="checkbox" name="segment[]" value="Class I-V Tuition" <?php if(in_array('Class I-V Tuition', $cats)) { echo "checked"; }?>> Class I-V Tuition
    

    这篇关于如何将JSON传递给复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 17:07