doushenyu2537
doushenyu2537
2017-11-02 01:33

在单个页面上显示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 dousongqiang2585 4年前
    <?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.

    点赞 评论 复制链接分享