php - 如何按类别 ID 包含两个文件

标签 php mysql if-statement include

我有一个文件,我想将另外两个文件放在这个文件中,它们将是动态的。主文件是这样的:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Gaming Ventus Let's Play - VLet's Play</title>
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="stylesheet" type="text/css" href="../styles/article_style_readmore.css">
<link rel="stylesheet" type="text/css" href="../../styles/styles_content_static_contact/styles_alltemplate_static_contact.css">
<link rel="stylesheet" type="text/css" href="../styles/readmore_mainbody_style.css">

<link rel="stylesheet" type="text/css" href="../../test/test2/Untitled-3.css">

</head>
<body>

<div id="wrapper">
  <div id="header">  
    <div id="top_header">
      <ul id="icons">
        <li><a href="http://youtube.com/" target="_blank"><img src="../../images/youtube-icon.png" alt="YT" width="32" height="32" /></a></li>
        <li><a href="http://facebook.com/" target="_blank"><img src="../../images/facebook-icon.png" alt="Fb" width="32" height="32" /></a></li>
        <li><a href="http://twitter.com/" target="_blank"><img src="../../images/twitter-icon.png" alt="Twit" width="32" height="32" /></a></li>
        <li><a href="http://google.com/" target="_blank"><img src="../../images/google-icon.png" alt="Goog" width="32" height="32" /></a></li>
        <li><a href="#" target="_blank"><img src="../../images/rss-icon.png" alt="Rss" width="32" height="32" /></a></li>
      </ul>        
    </div>

    <div id="bottom_header">
      <a href="../../index.php?page=home">
        <div id="logo"><img src="../../images/Ventus_Gaming_logo.png"></div>
      </a>
      <div id="search_bar">
        <form>
          <input type="text" id="search">
          <label for="search">Search</label>
        </form>
      </div>
    </div>
  </div>

  <div id="menu">
    <ul>
      <li><a href="../../index.php?page=home">Home</a></li>
      <li><a href="../../index.php?page=reviews">Reviews</a></li>
      <li><a href="../../index.php?page=news">News</a></li>
      <li><a href="../../index.php?page=videos">Videos</a></li>
      <li><a href="../../index.php?page=photos">Photos</a></li>
      <li><a href="../../content_static_main_body/contact.php?page=contact">Contact Us</a></li>
    </ul>
  </div>    

  <div id="main_body">
    <div id="main_left_nav">
  /****************************************************************\        
  <?php

    include('function_art_result_readmore.php');
    include('function_art_result_readmore_photos.php');

  ?>
  \****************************************************************/

    </div>

    <div id="right_nav">
      <div id="right_nav_about">
        About!
      </div>
      <div class="right_nav_others">
        Reviews!
      </div>
      <div class="right_nav_others">
        News!
      </div>
      <div class="right_nav_others">
        Videos!
      </div>
      <div class="right_nav_others">
        Photos!
      </div>
    </div>
  </div>

  <div id="footer">
    <p>Copyright Ventus Gaming</p>
  </div>
</div>

<?php
//Ayto einai to apotelesma otan patas to read more dhladh ta post mona tous
?>
</body>
</html>

所以在星号部分我有这两个文件,我想包括...这些文件有 mysql 代码和 php 代码。所以我想像这样包括它们:

<?php 
  if ($CatID == 8) {
    include('function_art_result_readmore.php');       
  } else {
    include('function_art_result_readmore_photos.php');
  }
?>

但这不起作用,仅作为示例。所以我想按类别 ID 打开包含文件,这样我就可以随时拥有这两个文件。 当然,如果有另一种解决方案,我接受 :)

提前致谢!

最佳答案

在请求中传递类别 ID(使用以下代码通过 GET 或 POST):

if(isset($_REQUEST['category_id']) &&  $_REQUEST['category_id'] == '8') {          
  include('function_art_result_readmore.php'); 
} else {  
  include('function_art_result_readmore_photos.php'); 
}

`

关于php - 如何按类别 ID 包含两个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765394/

相关文章:

php - Wordpress 正在页内导入我的链接样式表

php - 如何在 php mysql 博客中插入图像并在确切位置显示它们

php - 统计mysql表中的数据出现次数

java - 方法 createArrayOf 的 mysql JDBC 驱动程序出错

python - 圆计算器无法正常工作

php - Laravel 如何使用 FormRequest 验证多个文件(图像)

MySQL 数据库重复

java - 从数据库表中提取信息 php

batch-file - 批处理 : The syntax of the command is incorrect

mysql - 为什么 IF..NOT IN(subquery) THEN 不能与 MySQL 一起使用?