HTML动态创建表单条目


HTML create form entries dynamically?

我有一个包含来自页面的Facebook数据的JSON文件。我需要的是基于JSON文件创建一个具有checkbox条目的table。我正在使用php sdkjavascript sdk

我在想一种这样的方法:

<?php
$array_of_decoded=json_decode("$myjson",true);
for($i=0;$array_of_decoded(i);i++)
{?>
// create new entry in html form with the following propreties:
 <input type="checkbox" name="<?php array_of_decoded(i)['name']?>"
 value="<?php array_of_decoded(i)['id']?>"><?php array_of_decoded(i)['name']?<br>
<?php
//...
}?>

我的JSON文件有如下条目:

{"category":"Musician'/band","name":"Yann Tiersen (official)","id":"18359161762"}

我是一个新手,上面的代码可能是错误的,我只是当场写的,没有测试它。有人知道如何创建新条目吗?上面的代码是否显示了如何正确解码json ?

你可以使用" foreach ":

<?php
foreach(json_decode("$myjson",true) as $element) {?>
     <input type="checkbox" name="<?php echo $element['name']?>" value="<?php echo $element['id']?>"><?php echo $element['name']?><br>
<?php }?>

当然,这必须放在视图页面中!