• 技术文章 >后端开发 >php教程

    PHP用switch语句设计网站主页

    巴扎黑巴扎黑2016-12-28 17:27:26原创727
    一 PHP脚本

    index.php

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>switch语句的应用</title>
    <style type="text/css">
    <!--
    body {
    background-color: #F1EFEB;
    margin-left: 00px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    .STYLE4 {
    color: #154049;
    font-size: 13px;
    }
    a:link {
    text-decoration: none;
    color: #0A323C;
    }
    a:visited {
    text-decoration: none;
    color: #006600;
    }
    a:hover {
    text-decoration: none;
    color: #000033;
    }
    a:active {
    text-decoration: none;
    color: #003366;
    }
    -->
    </style>
    </head>
    <body><center>
    <table width="850" height="80" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="333" height="50">&nbsp;</td>
        <td width="90">&nbsp;</td>
        <td width="71">&nbsp;</td>
        <td width="74">&nbsp;</td>
        <td width="73" align="right">&nbsp;</td>
        <td width="75" class="STYLE4">返回首页</td>
        <td width="83" class="STYLE4">加入收藏</td>
        <td width="51">&nbsp;</td>
      </tr>
      <tr>
        <td height="30">&nbsp;</td>
        <td align="center">&nbsp;</td>
        <td align="center"><span class="STYLE4"><a href="index.php?lmbs=最新商品">&nbsp;最新商品</a></span></td>
        <td align="center"><span class="STYLE4"><a href="index.php?lmbs=热门商品">&nbsp;热门商品</a></span></td>
        <td align="center"><span class="STYLE4"><a href="index.php?lmbs=<?php echo urlencode("推荐商品");?>">推荐商品</a></span></td>
        <td align="center"><span class="STYLE4"><a href="index.php?lmbs=<?php echo urlencode("特殊商品");?>">特殊商品</a></span></td>
        <td align="center"><span class="STYLE4"></span></td>
        <td>&nbsp;</td>
      </tr>
    </table>
    <table width="850" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="196" height="520" align="center" valign="top"><table width="180" height="523" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#F1F1F1">
          <tr>
            <td height="25" align="center" bgcolor="#FFFFFF"><span class="STYLE4">&nbsp;&nbsp;<a href="index.php?lmbs=最新商品">&nbsp;最新商品</a></span></td>
          </tr>
          <tr>
            <td height="25" align="center" bgcolor="#FFFFFF"><span class="STYLE4">&nbsp;&nbsp;<a href="index.php?lmbs=热门商品">&nbsp;热门商品</a></span></td>
          </tr>
          <tr>
            <td height="25" align="center" bgcolor="#FFFFFF"><span class="STYLE4">&nbsp;&nbsp;&nbsp;<a href="index.php?lmbs=<?php echo urlencode("推荐商品");?>">推荐商品</a></span></td>
          </tr>
          <tr>
            <td height="25" align="center" bgcolor="#FFFFFF"><span class="STYLE4">&nbsp;&nbsp;&nbsp;<a href="index.php?lmbs=<?php echo urlencode("特殊商品");?>">特殊商品</a></span></td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
          <tr>
            <td height="25" bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
        </table></td>
        <td width="600" align="center" valign="top"><table width="595" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center" bgcolor="#FFFFFF">
    <?php 
    switch($_GET[lmbs]){
    case "最新商品":
            include "index1.php";
        break;
    case "热门商品":
            include "index2.php";
        break;
    case "推荐商品":
            include "index3.php";
        break;
    case "特殊商品":
            include "index4.php";
        break;
    case "":
            include "index4.php";
        break;
    }
    ?></td>
          </tr>
        </table></td>
        <td width="54">&nbsp;</td>
      </tr>
    </table>
    </center>
    </body>
    </html>

    index1.php

    <html>
    <head>
    <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <body>
    <imgsrc="images/bg6.jpg"width="508"height="543">
    </body>
    </html>

    index2.php

    <html>
    <head>
    <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <body>
    <ahref="index.php?lmbs=新品上市"></a>
    <imgsrc="images/bg7.jpg"width="547"height="548">
    </body>
    </html>

    index3.php

    <html>
    <head>
    <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <body>
    <a href="index.php?lmbs=<?php echo urlencode("特价区");?>"></a>
    <imgsrc="images/bg8.jpg"width="534"height="410">
    </body>
    </html>

    index4.php

    <html>
    <head>
    <metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <body>
    <imgsrc="images/bg7.JPG"width="538"height="520">
    </body>
    </html>

    二 运行结果

    3fe775e5-5390-3104-b548-46b4f9bdc633.png

    三 功能说明

    应用switch语句设计网站主页的布局,将网站头、尾文件设置为固定不变的板块、导航条也作为固定板块;而在主显示区中,应用switch语句根据超链接中传递的值不同,显示不同的内容。

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    上一篇:PHP页面输出搜索后跳转下一页的处理方法 下一篇:PHP中bom头引发的超级血案-head中的静态文件生成到body里面了
    线上培训班

    相关文章推荐

    • 你知道这个PHP命令行选项解析库(pflag)吗?• 带你看懂PHP中的class定义类与成员属性方法• PHP中如何才能将时间日期格式化?怎么计算时间差?• 最详细的教你PHP时间戳与日期时间的转换• 一定搞得懂PHP中如何添加图片水印

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网