PHP Question: How to fix these if/elseif statements

前端 未结 4 885
别跟我提以往
别跟我提以往 2021-01-23 16:30

I am trying to use these if/else if statements to display these php pages. The if/elseif statements allow for the php page to show up. The data is stored in the mysql. How do we

4条回答
  •  太阳男子
    2021-01-23 17:06

    Something like:

    $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.";
       }
    }
    

    I'm not sure exactly what you want to do if the page isn't found; or if subsequent records are duplicates.

提交回复
热议问题