doushenyu2537 2017-11-02 01:33
浏览 25
已采纳

在单个页面上显示PHP开关中的所有数据

I have a PHP switch that holds brief articles about a certain topic for the 50 U.S. states. For example, the content under ID 'ak' displays on the Alaska page...

<?php
switch($ID)
{
case 'ak':
?>
Text
<?php
break;
case 'ca':
?>
Text
<?php
break;
default:
break;
}

I designed it so that I can see the text and work on it in "plain view."

It works fine, but I just wondered if there's a simple way to display EVERYTHING in the switch on a single page. It could easily be done if the data was stored in a database, of course, but I don't know how to do it with a simple PHP switch.

I can do it manually, like this:

$ID = 'az';
echo '<h1>Arizona</h1>';
require($BaseINC."../../inc/view.php");
require($BaseINC."../../inc/eco/plants/flower.php");

$ID = 'wy';
echo '<h1>Wyoming</h1>';
require($BaseINC."../../inc/view.php");
require($BaseINC."../../inc/eco/plants/flower.php");

But I just wondered if there's an easier way.

One catch: I don't want to "kill" the ID's. Each ID may influence some of content displayed beneath that ID. So I guess a better way would be to give the display file some sort of universal ID that displays everything.

Note: Just to explain why I'm doing this, I was using Sigil to create epubs, but discovered I could manage my projects better using PHP, so I now want to create epubs in Dreamweaver, then import them into Sigil. I'm basically trying to create a simple test page.

  • 写回答

1条回答 默认 最新

  • dousongqiang2585 2017-11-02 03:02
    关注
    <?php
    $states = ['ak' => 'Arizona', 'ca' => 'California', 'wy' => 'Wyoming'];
    foreach ($states as $id => $stateName) {
        echo '<h1>' . $stateName . '</h1>';
        require($BaseINC."../../inc/view.php");
        require($BaseINC."../../inc/eco/plants/flower.php");
    }
    

    You can foreach loop to do this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图