duanfang2708 2018-01-23 14:12
浏览 149
已采纳

用php加载json内容到html表

i've the same search like mine alot here, but mine is a bit more complexe and didn't know how to make it work.

so i have this json content: (this is one of 84 objects inside a json table)

{
        "number": "6",
        "name": "Le Nickel : ses oxydes, ses sels et les opérations de grillage de mattes de nickel",
        "cause":
            {
                "A":"<p><strong><u>Liste indicative des principaux travaux</u></strong></p><p>Nickelage électrolytique des métaux</p>",
                "B": "<p><strong><u>Liste limitative des travaux</u></strong></p><p>Nickelage électrolytique des métaux</p><p>Opérations de soudage sur des métaux contenant du Nickel.</p>",
                "C": "<p><strong><u>Liste limitative des travaux</u></strong></p><p>Opérations de grillage de mattes de nickel. Opérations de soudage sur des métaux contenant du nickel.</p>"
            },
        "content": {
            "A": [
                {
                    "des": "Dermites eczématiformes récidivantes en cas de nouvelles expositions ou confirmées par test épicutané.",
                    "period": "7 jours"
                }
            ],
            "B": [
                {
                    "des": "Rhinite, asthme ou dyspnée asthmatiforme confirmés par test ou par épreuves fonctionnelles, récidivant après nouvelle exposition au risque.",
                    "period": "7 jours"
                }
            ],
            "C": [
                {
                    "des": "Cancer primitif de l’ethmoïde et des sinus de la face.Cancer bronchique primitif.",
                    "period": "40 ans"
                }
            ]
        }
    }

and i want to add them to this table based on search result

<tr>
            <th>Tableau</th>
            <th>Désignation des maladies</th>
            <th>Délai de prise en charge</th>
            <th>Liste indicative des principaux travaux susceptibles de provoquer ces maladies</th>
            <th></th>
        </tr>

when i search through the cause array everything works fine but when i loop through the content arrays thats when every thing just goes to hell.

this is my php code for the search:

$index = 0;
            $output ="";
            $first = "";
            $last = "";
                foreach($table["content"]["A"] as $content){
                    if(strpos($content["des"],$search)){
                        if($index == 0){
                            $first.= "<tr>";
                            $first.= "<td>".$table["number"]."</td>";
                            $first.= "<td>".$content["des"]."</td>";
                            $first.= "<td>".$content["period"]."</td>";
                            $$last.= '<td><a href="add.php"><button type="button">Ajoutez au suivi</button></a></td>';
                            $$last.= "</tr>";
                        }else{
                            $output.= "<tr>";
                            $output.= "<td>".$table["number"]."</td>";
                            $output.= "<td>".$content["des"]."</td>";
                            $output.= "<td>".$content["period"]."</td>";
                            $output.= '<td><a href="add.php"><button type="button">Ajoutez au suivi</button></a></td>';
                            $output.= "</tr>";
                        }
                        $index++;
                    }
                }
            echo $first;
            echo "<td rowspan=\"".$index."\">".$table["cause"]["A"]."</td>";
            echo $last;
            echo $output;
            $index =0;

and this is what happens when i run it :

result

i was hoping i find an answer here, thnks all for your time and for the help.

</div>
  • 写回答

4条回答 默认 最新

  • dongou2019 2018-01-23 14:20
    关注

    You can prepare table in php and display it with ajax/get. It will be easier to find a problem.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度