Title1

Title2

Title3

11-6 顯示單筆

一、流程


  #顯示單筆
  case "op_show":
    op_show($sn);
  break;

當新增、編輯記錄完成後,則顯示單筆記錄。

因此在新增的流程修改為:


  #新增記錄
  case "op_insert":
    $sn=op_insert();
    redirect_header("nav_m.php?op=op_show&sn={$sn}",3000,"新增資料成功!!");
  break;

二、函數


########################################
# 顯示單筆
########################################
function op_show($sn="")
{
  global $mysqli,$smarty;
  if(!$sn)redirect_header("index.php",3000,"查詢選單資料錯誤!!");

  #取得單筆記錄,可以寫成函數
  $sql = "select *
          from `show_kind`
          where `sn`='{$sn}' and `kind`='nav_home'";
  $result =  $mysqli->query($sql) or die(printf("Error: %s <br>".$sql, $mysqli->sqlstate));
  $DBV = $result->fetch_assoc();

  #過濾撈出資料
  $DBV['sn'] = intval($DBV['sn']);
  //http://www.w3school.com.cn/php/func_string_htmlspecialchars.asp
  $DBV['title'] = htmlspecialchars($DBV['title'], ENT_QUOTES); // 轉換雙引號和單引號
  $DBV['url'] = htmlspecialchars($DBV['url'], ENT_QUOTES); // 轉換雙引號和單引號
  $DBV['sort'] = intval($DBV['sort']);
  $DBV['enable'] = $DBV['enable'] ? "是":"<span style='color:red;'>否</span>";
  $DBV['target'] = $DBV['target'] ? "是":"<span style='color:red;'>否</span>";

  $smarty->assign("DBV", $DBV);
  return;
}


 

三、樣板


    {* 選單管理 顯示單筆 *}
    {if $WEB.file_name == "nav_m.php" and $op == "op_show"}
      <div class="container" style="margin-top:20px;">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h3 class="panel-title">顯示單筆</h3>
          </div>
          <div class="panel-body">

              <div class="row">
                <div class="col-md-6">
                  <div class="form-group">
                    <label>標題</label>
                    <div class="form-control">{$DBV.title}</div>
                  </div>
                </div>
                <div class="col-md-2">
                  <div class="form-group">
                    <label style="display:block;">外連狀態</label>
                    <div class="form-control">{$DBV.target}</div>
                  </div>
                </div>
                <div class="col-md-2">
                  <div class="form-group">
                    <label style="display:block;">啟用狀態</label>
                    <div class="form-control">{$DBV.enable}</div>
                  </div>
                </div>
                <div class="col-md-2">
                  <div class="form-group">
                    <label>排序</label>
                    <div class="form-control">{$DBV.sort}</div>
                  </div>
                </div>
              </div>

              <div class="form-group">
                <label>網址</label>
                <div class="form-control">{$DBV.url}</div>
              </div>

          </div>
        </div>
      </div>
    {/if}