常見輸出頁面:switch

簡單判斷可以用三目運算常用

判斷次數多的情況下考慮switch:

<td nowrap="true" valign="top"><span>
      <?php 
        switch ($attr['attr_input_type']){
          case 0:
            echo "手工錄入";
            break;
          case 1:
            echo "從下拉列表中選擇";
            break;
          case 2:
            echo "多行文本";
            break;
        }

      ;?>
      </span></td>

參考:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="application/views/admin/styles/general.css" rel="stylesheet" type="text/css" />
<link href="application/views/admin/styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="form-div">
  <form action="" name="searchForm">
    ![](application/views/admin/images/icon_search.gif)
    按商品類型顯示:<select name="goods_type" onchange="searchAttr(this.value)"><option value="0">所有商品類型</option>
    <?php foreach ($types as $type) :?>
      <option value="<?php echo $type['type_id'];?>" 
      <?php echo $type['type_id'] == $type_id ? "selected = 'selected'" : "" ?>
      ><?php echo $type['type_name'];?></option>
    <?php endforeach;?>
    </select>
  </form>
</div>

<form method="post" action="attribute.php?act=batch" name="listForm">
<div class="list-div" id="listDiv">

  <table cellpadding="3" cellspacing="1">
    <tbody>
        <tr>
            <th><input onclick="listTable.selectAll(this, &quot;checkboxes[]&quot;)" type="checkbox">編號 </th>
            <th>屬性名稱</th>
            <th>商品類型</th>
            <th>屬性值的錄入方式</th>
            <th>可選值列表</th>
            <th>排序</a></th>
            <th>操作</th>
        </tr>
      <?php foreach ($attrs as $attr) :?>
        <tr>
            <td nowrap="true" valign="top"><span><input value="1" name="checkboxes[]" type="checkbox">1</span></td>
            <td class="first-cell" nowrap="true" valign="top"><span onclick="listTable.edit(this, 'edit_attr_name', 1)"><?php echo $attr['attr_name'];?></span></td>
            <td nowrap="true" valign="top"><span><?php echo $attr['type_name'];?></span></td>
            <td nowrap="true" valign="top"><span>
      <?php 
        switch ($attr['attr_input_type']){
          case 0:
            echo "手工錄入";
            break;
          case 1:
            echo "從下拉列表中選擇";
            break;
          case 2:
            echo "多行文本";
            break;
        }

      ;?>
      </span></td>
            <td valign="top"><span><?php echo $attr['attr_value'];?></span></td>
            <td align="right" nowrap="true" valign="top"><span onclick="listTable.edit(this, 'edit_sort_order', 1)">0</span></td>
            <td align="center" nowrap="true" valign="top">
                <a href="index.php?p=admin&c=attribute&a=edit&attr_id=<?php echo $attr['attr_id'];?>" title="編輯">![](application/views/admin/images/icon_edit.gif)</a>
                <a href="index.php?p=admin&c=attribute&a=delete&attr_id=<?php echo $attr['attr_id'];?>" onclick="removeRow(1)" title="移除">![](application/views/admin/images/icon_drop.gif)</a>
            </td>
        </tr>
    <?php endforeach;?>

      
      </tbody></table>

  <table cellpadding="4" cellspacing="0">
    <tbody><tr>
      <td style="background-color: rgb(255, 255, 255);"><input type="submit" id="btnSubmit" value="刪除" class="button" disabled="true"></td>
      <td align="right" style="background-color: rgb(255, 255, 255);">      <!-- $Id: page.htm 14216 2008-03-10 02:27:21Z testyang $ -->
            <div id="turn-page">
        <?php echo $pageinfo;?>
        <!--
        總計  <span id="totalRecords">12</span>
        個記錄分為 <span id="totalPages">2</span>
        頁當前第 <span id="pageCurrent">1</span>
        頁,每頁 <input type="text" size="3" id="pageSize" value="10" onkeypress="return listTable.changePageSize(event)">
        <span id="page-link">
          <a href="javascript:listTable.gotoPageFirst()">第一頁</a>
          <a href="javascript:listTable.gotoPagePrev()">上一頁</a>
          <a href="javascript:listTable.gotoPageNext()">下一頁</a>
          <a href="javascript:listTable.gotoPageLast()">最末頁</a>
          <select id="gotoPage" onchange="listTable.gotoPage(this.value)">
            <option value="1">1</option><option value="2">2</option>          </select>
        </span>
        -->
      </div>
</td>
    </tr>
  </tbody></table>
</div>

</form>

<div id="footer">
    
</div>
<script type="text/javascript">
   function searchAttr(type_id){
      var url = "index.php?p=admin&c=attribute&a=index&type_id="+type_id;
      window.location.href = url ;
   }
</script>
</body>
</html>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • 1. Java基礎部分 基礎部分的順序:基本語法,類相關的語法,內部類的語法,繼承相關的語法,異常的語法,線程的語...
    子非魚_t_閱讀 31,739評論 18 399
  • 一、中藥服用 服中藥時禁忌:蔥蒜,胡椒,羊肉,狗肉,茶葉,蘿卜,魚 二、具體藥材 1、白芨①中文名:白芨②界:植物...
    瀟湘妃子JC閱讀 242評論 0 0
  • 夜已經深了,坐在幽暗的燈光下,手中握著文學大師郁達夫的作品,郁達夫就這樣撲面走來,而我,也沉浸在他孤獨的氣質和深沉...
    絳洞花王閱讀 9,037評論 34 63
  • 有時候 看到一個男孩子 會看穿他的內心 會理解他的一切 這太不可思議 而我不知道我會有這樣的功能。
    相相相柳閱讀 79評論 0 0
  • 萌貓“胖花”的主人Yixi有事回國一個月,走之前把寵貓托付給了我。我和Alex (以下稱輕松熊)早就滿懷期待,代管...
    Shou撕鬼子閱讀 517評論 0 3