dqteh7347 2012-11-11 12:57 采纳率: 100%
浏览 25

使用PHP进行基本导航



We have a school project with HTML/PHP, and we need to create a web page. The problem is there can only be a index (or a main page), the rest of them are small portions of code in other .html documents.

I need to find a way to create a function (I think...) so when I click on one of the links, this will change the <body id>, the <title>, and will load a different content in a <div> (the small portion of code).

Resuming: there are 5 categories, when clicked, each one of them should change the <body id> attribute, the <title>, and load a different .html page in the <div>. I'm sorry if some of you find this offensively lame, but I really need some help with this.

Until now, this is what i have:

<?php
    $id0="" . $id1;     //default
    $id1="home";
    $id2="iso";
    $id3="lm";
    $id4="par";
    $id5="itasir";
    $id6="fh";
?>

<body id="<?php echo $id0; ?>">

Where $id1-6 should be the categories, and the id0 would be the counter or a pointer of the page that should be loaded. Ex. When I click on the "Par" link, $id0 would change to "" . $id4; and the body would load the id0 which contains id4 now... i think... That should be it.

Thanks...

  • 写回答

1条回答 默认 最新

  • douan3182 2012-11-11 13:21
    关注

    A few things to read – learning is awesome, but of course just being given the code sucks.

    <?php
        $id0="" . $id1;     //default
        $id1="home";
        $id2="iso";
        $id3="lm";
        $id4="par";
        $id5="itasir";
        $id6="fh";
    ?>
    

    Would make much more sense as:

    <?php
        $id = array();
        $id[0]="" . $id[1];
        $id[1]="home";
        $id[2]="iso";
        $id[3]="lm";
        $id[4]="par";
        $id[5]="itasir";
        $id[6]="fh";
    ?>
    

    That way you can easily use numbers to get the one you need.

    You are probably going to use variables in the URL using $_GET.

    If the URL is http://www.example.com/index.php?page=1, then $_GET['page'] would be equal to 1.

    That lets you write some PHP that does different things based on the URL.

    You will then likely use file_get_contents (http://php.net/manual/en/function.file-get-contents.php) to load in the contents of the right file.

    Easy!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题