$ _GET ['value']作为指针的动态页面内容

时间:2018-08-14 11:23:07

标签: php mysql

我创建了一个动态菜单。对于我设置的每个菜单项

"<li>" . "<a href=\"content.php?page=" . urlencode($pages["menu"]) . "\">" . $pages["menu"] . "</a>" . "</li>"

我的下一个计划是获取$ _GET ['page']并将其放入变量

if (isset($_GET['page'])) {
      $page_id = $_GET['page'];
    }

然后创建另一个查询

$query = "SELECT * ";
  $query .= "FROM ccms.pages ";
  $query .= "WHERE p.menu =" . $page_id;
  $query .= " LIMIT 1";

然后回显p.content。

一切都按计划进行,除了最后一部分。

如果我的方法完全歪曲,甚至愚蠢,请指向另一个方向。如果还算不错,为什么我没有得到任何结果?甚至没有错误消息。

我的完整代码如下:

content.php

<?php
    require_once 'includes/connect.php';
    if (isset($_GET['page'])) {
      $page_id = $_GET['page'];
    }
    require_once("includes/functions.php");
    include("includes/header.php");
?>

    <div id="nav">
        <ul style="font-size:22px;">
            <?php
            $info_set = get_all_info();

            while($information = $info_set->fetch(PDO::FETCH_ASSOC)){
            echo "<li>" . "<a href=\"content.php?info=" . urlencode($information["menu"]) .
            "\">" . $information["menu"] . "</a>" . "</li>"; 

            $page_set = get_pages_for_info($information['id']);

            echo "<ul style=\"font-size:16px;\">";

            while($pages = $page_set->fetch(PDO::FETCH_ASSOC)){
            echo "<li>" . "<a href=\"content.php?page=" . urlencode($pages["menu"]) .
            "\">" . $pages["menu"] . "</a>" . "</li>"; 
            }
            echo "</ul>";   
            }
            ?>
            </ul>
        </div>

    <div id="content"> 

        <h4><?php get_info_by_id() ?></h4>


        <?php $page = get_page_by_id($Page_id); ?>



    </div> <!--end of main content-->

<?php require("includes/footer.php");?>

functions.php

<?php

function get_all_info(){
    global $db;
    $query = "SELECT * FROM ccms.information ORDER BY position ASC";
    $info_set = $db->prepare($query);                
    $info_set->execute();
    return $info_set;
}


function get_pages_for_info($information_id){
    global $db;
    $query = "SELECT * FROM ccms.pages p where p.information_id = :iid ORDER BY position ASC";
    $page_set = $db->prepare($query);                
    $page_set->bindParam(':iid', $information_id);
    $page_set->execute();
    return $page_set;
} 

function get_info_by_id() {
    if (isset($_GET['info'])) {
      $id = $_GET['info'];
      echo $id;
    }
}

function get_page_by_id($page_id) {
  global $db;
  $query = "SELECT * ";
  $query .= "FROM ccms.pages ";
  $query .= "WHERE p.menu =" . $page_id;
  $query .= " LIMIT 1";
  $result_set = $db->prepare($query);
  $result_set->execute();
  if($page = $result_set->fetch(PDO::FETCH_ASSOC)){
    return $pages['id'];
  } else {
    return NULL;
  }  
}

?>

0 个答案:

没有答案