首页 \ 问答 \ 多个html页面v / s单个html页面[关闭](Multiple html pages v/s Single html page [closed])

多个html页面v / s单个html页面[关闭](Multiple html pages v/s Single html page [closed])

我正在尝试为一个小项目创建一个网站。 您在浏览器窗口中启动后访问的第一个页面是一个登录页面,它提供了从多个选项中选择一个的方法。 例如,选择您想要访问的内容 -

1. 2. 3. 4.依此类推

我正在使用基本的html,css和javascript来处理这个问题,因为那些是我熟悉的。 话虽如此,如果能让工作变得更轻松,我愿意学习别的东西。

但目前,我的问题是我为初始登陆页面设计了一个html页面,当用户选择一个选项时,我正在考虑使用链接将他转移到新的网页。

是否应该为每个选项都有一个单独的html页面,因为每个选项可能会有所不同,但不是主要的。

对不起,我尝试在线寻找解决方案,但我不确定如何说出我的搜索字词。 另外,我在堆栈溢出中发现的唯一另一件事是如何使用单个index.html显示多个html页面

任何帮助或指导将非常感激。 谢谢!


I'm trying to create a website for a small project. The first page you reach after launching it in a browser window is a landing page that provides means to pick one of multiple options. E.g. Pick what you'd like to access -

1. 2. 3. 4. and so on

I'm using basic html, css and javascript to work on this, since those are the ones I'm somewhat familiar with. That being said, I'm open to learning something else if it makes the job much easier.

But at the moment, my problem is I have designed an html page for the inital landing page and when the user picks an option, I'm thinking of using links to transfer him to a new webpage.

Should there be a separate html page for each of these options, given that each may be a little different, but not majorly.

I'm sorry, I tried looking online for a solution but I'm not sure how I can word my search terms. Also, the only other thing I found on stack overflow was How to display multiple html pages using single index.html

Any help or guidance would be most appreciated. Thanks!


原文:https://stackoverflow.com/questions/37757562
更新时间:2021-11-02 19:11

最满意答案

知道了您期望的JSON数据的结构,您可以使用JSON数据在foreach循环中动态构造表,如下所示:

    <?php   
        $result     = curl_exec($ch);
        curl_close($ch);

        $json       = json_decode($result);

        // BUILD THE TABLE INITIAL HEADER SECTION
        $strTableOutput     = "<table class='reservation-tbl' id='reservation-tbl'>"    . PHP_EOL;
        $strTableOutput    .= "<tr class='reservation-header-row'>"                     . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Client ID</th>"      . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Property</th>"       . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Property Name</th>"  . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>First Name</th>"     . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>LastName</th>"       . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>E-Mail</th>"         . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Price</th>"          . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>From</th>"           . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Till</th>"           . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Status</th>"         . PHP_EOL;
        $strTableOutput    .= "</tr>"                                                   . PHP_EOL;
        $strTableOutput    .= "<tbody class='reservation-body'>"                        . PHP_EOL;


        // LOOP THROUGH THE JSON DATA & BUILD EACH ROW USING THE
        // DATA PROVIDED BY THE JSON OBJECT
        foreach ($json->data->reservations as $element) {
            $strTableOutput .= "<tr class='reservation-data-row'>"  . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->id}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->property}<br /><a href='{$element->infourl}' target='_blank'>{$element->infourl}</a></td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->propertyName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->firstName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->lastName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->email}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->price}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->from}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->to}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->status}</td>" . PHP_EOL;
            $strTableOutput .= "</tr>" . PHP_EOL;
        }
        // CLOSE THE TABLE-BODY AND THE TABLE 
        $strTableOutput    .= "</tbody>"    . PHP_EOL;
        $strTableOutput    .= "</table>"    . PHP_EOL;

        // DISPLAY THE HTML REPRESENTATION OF YOUR STRUCTURED TABLE-DATA
        echo $strTableOutput;

Knowing the Structure of the JSON Data you expect, you can dynamically construct a Table within a foreach Loop using the JSON Data like so:

    <?php   
        $result     = curl_exec($ch);
        curl_close($ch);

        $json       = json_decode($result);

        // BUILD THE TABLE INITIAL HEADER SECTION
        $strTableOutput     = "<table class='reservation-tbl' id='reservation-tbl'>"    . PHP_EOL;
        $strTableOutput    .= "<tr class='reservation-header-row'>"                     . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Client ID</th>"      . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Property</th>"       . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Property Name</th>"  . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>First Name</th>"     . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>LastName</th>"       . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>E-Mail</th>"         . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Price</th>"          . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>From</th>"           . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Till</th>"           . PHP_EOL;
        $strTableOutput    .= "<th class='reservation-header-cell'>Status</th>"         . PHP_EOL;
        $strTableOutput    .= "</tr>"                                                   . PHP_EOL;
        $strTableOutput    .= "<tbody class='reservation-body'>"                        . PHP_EOL;


        // LOOP THROUGH THE JSON DATA & BUILD EACH ROW USING THE
        // DATA PROVIDED BY THE JSON OBJECT
        foreach ($json->data->reservations as $element) {
            $strTableOutput .= "<tr class='reservation-data-row'>"  . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->id}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->property}<br /><a href='{$element->infourl}' target='_blank'>{$element->infourl}</a></td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->propertyName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->firstName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->lastName}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->clientInfo->email}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->price}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->from}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->to}</td>" . PHP_EOL;
            $strTableOutput .= "<td class='reservation-data-cell'>{$element->pricing->status}</td>" . PHP_EOL;
            $strTableOutput .= "</tr>" . PHP_EOL;
        }
        // CLOSE THE TABLE-BODY AND THE TABLE 
        $strTableOutput    .= "</tbody>"    . PHP_EOL;
        $strTableOutput    .= "</table>"    . PHP_EOL;

        // DISPLAY THE HTML REPRESENTATION OF YOUR STRUCTURED TABLE-DATA
        echo $strTableOutput;

相关问答

更多
  • 在你的for循环中得到这个: for (var i = 0; i < tdata.length; i++) { response += '
    ' + '' + '' + '' + '' + '
    • 你可以试试这个Javascript解决方案: 假设 所有data属性的值都有相同的数组长度 给定数组中的第一项包含每一行的标题 var arr = [{ "name": "External System", "data": ["CHAT", "EMAIL", "EVENTMANAGEMENT", "INSTANTMESSAGING", "PHONECALL", "SELFSERVICE"] }, { "name": "CANCELLED", "data": [0, 2, 263, ...
    • var jsondata=[{id:1,name:"Mani",subject:"English",Score:88},{id:1,name:"Mani",subject:"Maths",Score:65},{id:2,name:"Ram",subject:"English",Score:75},{id:3,name:"Kumar",subject:"English",Score:15},{id:3,name:"Kumar",subject:"Science",Score:88}]; var head ...
    • 既然你说JSON正在回归,并且假设问题中的对象结构是正确的,那么我会发现一些事情: 1)我不明白为什么这行var tr = data.report在代码中。 您将tr设置为已获取的数据,然后在循环中使用jquery对象覆盖它。 2)您无法从JSON中获取数据的原因是data是对象的根。 您尝试写入表的data位于顶级data对象的report属性中。 您可以将您的javascript更新为: for (var i = 0; i < data.report.length; i++) { var tr = ...
    • 知道了您期望的JSON数据的结构,您可以使用JSON数据在foreach循环中动态构造表,如下所示:
    • 写下你希望的代码。