我正在尝试使用这些if / else if语句来显示这些PHP页面. if / elseif语句允许显示PHP页面.数据存储在mysql中.我们如何获得它,以便如果它已经显示过,它只能输入一次?谢谢.希望您能提供帮助.抱歉,这有点令人困惑.我最近才学英语.
谢谢.
if ($result_array[0] = Politics) {
require 'news/political.PHP';
} elseif ($result_array[0] = Gossip) {
require 'news/celebgossib';
} elseif ($result_array[0] = Entertainment) {
require 'news/entertainment.PHP';
} elseif ($result_array[0] = Finance) {
require 'news/finance.PHP';
} elseif ($result_array[0] = Health) {
require 'news/health.PHP';
} elseif ($result_array[0] = Leisure) {
require 'news/leisure.PHP';
} elseif ($result_array[0] = Sports) {
require 'news/sports.PHP';
} elseif ($result_array[0] = Tech) {
require 'news/tech.PHP';
} elseif ($result_array[0] = World) {
require 'news/world.PHP';
} else {
echo "There is no interests in your database";
}
if ($result_array[1] = Politics) {
require 'news/political.PHP';
} elseif ($result_array[1] = Gossip) {
require 'news/celebgossib';
} elseif ($result_array[1] = Entertainment) {
require 'news/entertainment.PHP';
} elseif ($result_array[1] = Finance) {
require 'news/finance.PHP';
} elseif ($result_array[1] = Health) {
require 'news/health.PHP';
} elseif ($result_array[1] = Leisure) {
require 'news/leisure.PHP';
} elseif ($result_array[1] = Sports) {
require 'news/sports.PHP';
} elseif ($result_array[1] = Tech) {
require 'news/tech.PHP';
} elseif ($result_array[1] = World) {
require 'news/world.PHP';
} else {
echo "There is no interests in your database";
}
解决方法:
就像是:
$pages = array(
'Politics' => 'political',
'Gossip' => 'celebgossib',
...
);
$used = array();
for ($i = 0; $i < 2; ++$i)
{
if (array_key_exists($result_array[$i], $pages)
{
if (!array_key_exists($result_array[$i], $used))
{
# only display this section once
include 'news/'.$pages[$result_array[$i]].'.PHP';
$used[$result_array[$i]] = true;
}
}
else
{
echo "nothing to see here.";
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。